Binding Client Side Script to the onLoad event using crm.ready()

Less than one minute read time.

Sage CRM has a Client Side method crm.ready() which is used to execute scripts once the page is loaded.

We do not have to worry whether the browser is Chrome or Internet Explorer. The crm.ready() method will take the browser version into account and add the function we pass to it in the correct way.

crm.ready(function(){
//function script goes here

})

The crm.ready() will execute the scripts as soon as the page's DOM hierarchy has been fully constructed. The function passed to crm.ready() is guaranteed to be executed after the DOM is ready. It is actually tied to loading of the document object, so this is the ideal location to run other crm clientside code.

The following example script can be added to the custom content box of the CompanyBoxLong screen and will highlight in red the comp_status field when the value of the field is 'Closed'.

The code below needs to go into "<" script ">" tags.

crm.ready(function(){
if (crm("comp_status").value()== "Closed")
{
crm("comp_status").highlight("red");
}
})