Monday, October 19, 2009

OnLoad, Onsave and OnChange code sharing/reuse in MS CRM 4.0

There are three events in CRM form, OnLoad, OnSave, OnChange. OnLoad and OnSave are in the form level and OnChange is in field level. Sometimes it’s needed to write the same code/method in OnLoad, or Onsave or OnChange or all three events.

Actually these events trigger in a sequence, first OnLoad then OnChange (if any) and finally OnSave. So whatever methods we have written in the OnLoad of the form it will be available in OnChange and OnSave of the form.

If there are any method/methods in OnLoad event we can reuse those methods in OnChange event of any field and OnSave of the form just by calling the method (no need to redefine the method definition again).

And also sometimes it’s required to write the same code what we have in OnChange of any field in OnLoad/OnSave. We can achieve the same just by calling the OnChange code of the field using “<field_Schema>_onchange0();” method.


Patrick O'Riley said...

I'm not sure if you can help out with my situation, but I am using a blogger widget called scrippets that converts text from posts into proper screenwriting format. In order for this widget to function, I had to change my < body > code in my template to < body onload='convert();' >. As a result, my archives no longer collapse and my Google Friend Connect widget suddenly empties. Can you think of any way I can have my cake and eat it too? Or do I need to choose between collapsing archives and my scrippets function? If you have no idea then I apologize and thank you for your time. I think this conflict affects very few blogspot users, perhaps only one.

Anonymous said...

Useful, handy and "easy-to-understand" descriptions!