Search This Blog

Monday, June 27, 2022

JavaScript and Business Rule on the same field

 Recently, on change of value of a field, we had business rule earlier and then we decided to perform the same using JavaScript to avoid hard coding of value in Business rule. The logic was to set value of 2 other fields on the form based on the value selected.

The logic was working fine on DEV as we had deactivated the business rule. However, after deploying to TEST and UAT, it stopped working.

We verified that the JavaScript event handler was enabled for the OnChange event of that field.

image

While debugging the code as well using browser console, we checked that the break point was hitting the code block where we were setting the value of 2 other fields.

image

After struggling for few minutes, it came to our mind that Business rule was also written which should have been deactivated.

image

The business rule was basically clearing the values of the 2 fields if the selected value of field was not in the condition anywhere.

image

After deactivating the business rule, closing the form, opening it again when we tested it, it worked.

So, if we have JavaScript and Business Rule written on the same field, then the order of execution is first JavaScript then Business Rule for which even if the values of the 2 fields were set using JavaScript were getting cleared by the Business Rule.

 Or 

In Dynamics crm ff you have both javascript and business rules on same form then it follow below order:

  1. Any system script is applied first
  2. Custom javascript
  3. Business rule, In case multiple business rule exist on same event, they run in the order they were activated. Means the one which was activated first will execute first and the one activated last will execute at last.



No comments:

Post a Comment