Trigger OnLoad Workaround for AJAX issues in CRM 2013

I thought I’d create a quick post as I was required to use a workaround for a client today involving an OnLoad event that wasn’t being called correctly in Microsoft Dynamics CRM 2013.

The background on this is that the AJAX used to refresh the page in CRM 2013 doesn’t necessarily call the OnLoad action, in this case it was affecting the JavaScript used to switch the Account from base on the value “Account Type” option set.

I remembered that a colleague had mentioned this in the past and advised that there was indeed a workaround using configuration, namely;

  • 1 x Boolean field
  • 1 x Synchronous Workflow
  • Update to the fields OnChange event

So what do you do?

Step 1 – Create a new Boolean (Two Option) field for the entity or entities effected. In my client’s case it was Account, using the following steps; Settings > Solutions > Choose Your Solution and Open it > Entities > Account > Fields > New.

Then make sure you add a display name that will make sense to you, set the “Field Requirement” to “Optional” and set the “Type” option to “Two Options”, then click Save and Close.

boolean_triggerfield

Step 2 – Next add the new field to the required forms against your entity, then click “Change Properties” on your field and uncheck “Display Label on the Form” and “Visible by Default” and also check “Lock the Field on the Form” (this will endure admin’ users will have to think twice before removing the field) then click “OK” to close the box. Next click Save and then Publish your changes and close the form (still no button for Save, Publish and Close), repeat for other forms as required.

properties_triggerfield

Step 3 – Create a new Synchronous Workflow (real-time) Process against the entity with “Organisation” as the scope (in this case Account) in CRM that is triggered when;

  • Record is created
  • Record status changes
  • Record fields change (check the required fields to apply this workflow to)

Add a workflow step to update the entity (in this example Account) and in the “View Properties” area select the Boolean we just added and set the field value to “Yes”. Save and Activate the workflow.

Please Note; be careful to select the right option in the “execute as” property, if the owner of the workflow is the system admin’ account then you should have no issues, if it is the user who made the changes, then you will have to consider their security role for the entity.

Step 4 – Finally add the JavaScript from your OnLoad that switches the form etc. to the OnChange event of the new Boolean field in your entity form. You can find this under the field by navigating to; Change Properties > Events > OnChange > Event Handlers > Add.

Remember to add the function in minus “()”. Then click “OK” and Save, Publish and Close. Repeat as required for other forms.

Don’t’ forget to test your changes and you are done.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s