In order to address that issue I have decided to write a series of How-To posts which are simple and usually address a specific requirement.
The how-to posts are categorized by common client side development tasks like CRM Form, CRM Fields, CRM IFRAME, CRM Lookup and so on. Each time something new comes up I’ll simply update the relevant “Repository” How-To post. If you have a specific requirement that you don’t see in my post and you feel that should be then comment on that and if it is missing I’ll share that solution when I can.
This How-To post addresses CRM Form development tasks:
Addressing Form Type (crmForm.FormType) in script.
This should be the BASIC TEMPLATE for all your scripts. Since crmForm has more then 1 state (type) your code should always address that.
If for example the create and update Types share the same code than simply put your code in one method and call it from the other.
/* Form Types */
var FormTypes =
Undefined : 0,
Create : 1,
Update : 2,
ReadOnly : 3,
Disabled : 4,
QuickCreate : 5,
BulkEdit : 6
/* Script Entiry Point */
switch( crmForm.FormType )
/* Implement each Form Type you wish to address */
Change Field Required level
Parameter1 - Field scheme name
Parameter2 - is required
crmForm.SetFieldReqLevel( "<FieldId>" , true );
Check if the form has changed ( by user or code ) Since it was loaded
alert( crmForm.IsDirty() );
Binding to crmForm save event
This coding method is easier to manage and more productive then putting your code In the OnSave event box.
crmForm.attachEvent( "onsave" , OnCrmPageSave );
This relates to the former bullet.
The code checks the form validity. If its not valid then The returnValue is set to false and the form save does not fire.
var valid4Submit = true;
if( /* Form Is NOT Valid */ )
valid4Submit = false;
return (event.returnValue = valid4Submit);
Retrieve Entity Object Type Code
alert( crmForm.ObjectTypeCode );
Retrieve Entity Schema Name
alert( crmForm.ObjectTypeName );
Remove (detach) MS window close alert