Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Fire a Business Rule after a field is updated using JavaScript

Posted on by 40

Hi

I am updating a field dynamically, let's call it fieldX, using JavaScript using the setValue() function. 

This particular field is one of 3 fields used by a business rule to update a fourth field.

The problem that I have is that the business rule fails to fire after being updated by JavaScript.

Does anyone know of a novel way to trigger the Business Rule to fire and use the new 

The obvious fix is to update the fourth field from within the JavaScript but this is duplication of the Business Rule and I would like a more elegant solution if possible.

Another option could be to setFocus on fieldX after the update but this would require the user to click off the field, and I haven't tested yet if this would fire the Business rule.

*This post is locked for comments

  • yleclerc Profile Picture
    yleclerc 1,545 on at
    RE: Fire a Business Rule after a field is updated using JavaScript

    As always, Andrew is the man!

  • Suggested answer
    Viswanath Profile Picture
    Viswanath 90 on at
    RE: Fire a Business Rule after a field is updated using JavaScript

    For My Case, Karsten's reply is the correct answer.

    Thanks

    Karsten.

  • Rob Nightingale Profile Picture
    Rob Nightingale 40 on at
    RE: Fire a Business Rule after a field is updated using JavaScript

    Hi Erik

    I assumed this was the case but its good to see the background documentation supporting the logic!

    Thanks.

  • Rob Nightingale Profile Picture
    Rob Nightingale 40 on at
    RE: Fire a Business Rule after a field is updated using JavaScript

    Thanks Andrii, this worked like a charm!

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Fire a Business Rule after a field is updated using JavaScript

    Andrew's answer will probably solve your problem, but you could also check at what scope you're running the business rule. I'm not sure about this but if you've put the Business rule scope to Entity, it will run server-side and the JS may not trigger a change (whereas it might if you run it on form).

    JS should trigger onChange by default as long as the business rule doesn't manipulate the trigger fields themselves as that would cause a loop:

    "When you set a field value by using a business rule, any OnChange event handlers for that field will not run. This is to reduce the potential for a circular reference, which could lead to an infinite loop." (https://technet.microsoft.com/en-us/library/dn531086(v=crm.6).aspx#BKMK_Limitations)

  • Karsten Wirl Profile Picture
    Karsten Wirl 4,477 on at
    RE: Fire a Business Rule after a field is updated using JavaScript

    Hi Rob.

    Are the fields empty before your JavaScript set a value?

    Kind regards,

    Karsten

  • Verified answer
    a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: Fire a Business Rule after a field is updated using JavaScript

    Hello Rob,

    Have you tried to use fireOnChange method after you set the field value? - msdn.microsoft.com/.../gg334409.aspx

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans