joi, 15 aprilie 2010

CRM, OnSave, Activate/Deactivate and changing form fields

A little thing i learned today while cursing and swearing the hell out of CRM is how to change the value of a field when activating/deactivating an entity in CRM 4.0 (The cursing and swearing is, mostly, due to my being a true CRM newb, but CRM has it's faults too. Oh yeah...:)
The scenario is this: When deactivating or reactivating and entity in CRM 4.0, change the value of a field in your form and save it to the db.
Long story short to achieve this goal you must do the following:
1. Customize the OnSave event of the form
2. Check the event.Mode value (remember that 5 is deactivate, while 6 is reactivate)
3. Change the DataValue property of your desired field to whatever you want
5. Throw in some ForceSubmit = true for good measure

So, your code for the OnSave event might look like this
Code:
         if(event.Mode == 5/*Deactivate*/)
           {
                crmForm.all.yourField.DataValue = xxxxxx;
                crmForm.all.yourFiled.ForceSubmit = true;
          }
        if(event.Mode == 6/*Reactivate*/)
           {
                crmForm.all.yourField.DataValue = yyyy;
                crmForm.all.yourFiled.ForceSubmit = true;
          }


Enjoy:)

Niciun comentariu:

Trimiteți un comentariu