Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM forum
Suggested answer

Business Rule on Form load

Posted on by Microsoft Employee

Hi

I have a parameterized entity form. Based on the parameter, i am setting an attribute value (E.g RequestType  which is an Optionset type) using the script on form load. I have a requirement, i need to show/hide couple of fields based on the parameter.

I wrote a business rule, setting a SetVisibility rule for those fields based on the "RequestType". The scope of the Business rule is "Specific Form" (I tried setting All forms as well).

It appears that the Business rule does not considering the RequestType value which i was setting on form load and executes other condition. But it executes correctly when opening the existing record.

That clarifies me - the value which i was setting on form load does not passing through Business rule on form load.

Can some one help me how to overcome this issue? How to use business rule?

Thanks in advance.

 

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Business Rule on Form load

    Thank you @Raz CRM and @Masoor Sulaiman for your responses and attention...

    I would like to understand more on my scenario. Please try to help me.

    Rule 1 from the document/TechNet etc

    • 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.

    Question: Is this applicable in vise versa as well?

    In my case I am setting the value dynamically to a field where the business rule is defined to execute based on the value.

    Rule 2 from your response /TechNet etc - Execution order

    The logic included in your business rules is applied together with other logic in the form that could include system scripts, custom scripts, and other business rules. The order in which this logic is applied will affect the outcome. The order is as follows:
    1. Any system scripts are applied first.
    2. Any logic in custom form scripts is applied.
    3. Logic in business rules is applied.

     When there are multiple business rules, they are applied in the order they were activated, from oldest to newest.
    4. The Entity scope business rules are executed on the server, after the synchronous plug-ins.

    Question: My code also follows the same execution sequence

    1. not concerned 2. My form load 3. Business rule

    Why it is not executing correctly? Any further insight would be appreciated.

    ================================================================

    Other thought process:
    I read somewhere; the CRM generates the scripts and embed along with the form when the business rules are defined with the scope form level and/or all forms. So that it executes at client side. This is equivalent to the Validator controls in ASP.Net. 

    Question: If the above is correct, then it should work in my scenario. correct?

    Also I would like to highlight - In my scenario, instead of setting the optionset dynamically through form load, After the form loads, if choose or chnage the optionset value then the business rules works and dependent fields hide/unhide accordingly.

    Please help me to understand the business rules correctly. Also correct me if my thought process or analysis is wrong.

    Thanks in advance and appreciate your time.   

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Business Rule on Form load

    Hi,

    Please read below to get idea on limitations of business rules.

    koenvandevyver.wordpress.com/.../limitations-for-business-rules-in-crm20132015

    Mansoor

  • Suggested answer
    razdynamics Profile Picture
    razdynamics 17,304 User Group Leader on at
    RE: Business Rule on Form load

    Hi Sree

    Fields updated through Business Rules do not trigger the fields on change event of JavaScript. best practice would be not to mix them both because it will be harder to maintain, and makes the solution more complex for developers. It is also good to note the Execution order:

    -System JavaScripts (source code by Microsoft)

    -Custom Javascript

    -Business Rules

    Another factor to keep in mind when deciding whether to implement business logic via javascript or a business rule is this: We cant control  when a business rule is fired as It is always being enforced, whereas with javascript we can control.

    so it might be better to code this logic all in javascript rather than a business rule

    I hope this answers your question, Kindly Verify :)

    Best Wishes, Raz

    Microsoft Dynamics CRM Training Instructor

Helpful resources

Quick Links

Replay now available! Dynamics 365 Community Call (CRM Edition)

Catch up on the first D365 Community Call held on 7/10

Community Spotlight of the Month

Kudos to Saurav Dhyani!

Congratulations to the June Top 10 community leaders!

These stars go above and beyond . . .

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 287,696 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 225,490 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans