In my previous post I built a Business Rule to do simple calculations. For the sake of simplicity I purposedly left out the simple housekeeping that most people will want to do i situations like the one I used in the example.
In this post I'll show you how the logic in the above example can be extended a bit, by invoking a second rule (set a field value and hide a field). In addition to invoking a second rule, I'll edit my original rule to make sure a field ("Result") is visible if the user opts for automatic calculations.
On a side note - this example also shows you how to implement "If-Then-Else" logic using an option field and two rules, firing for respectively option 1 and option 2.
So, continuing my example from the post "CRM 2013: Understanding Portable Business Logic"
- I revisit my Account entity and the underlying Business Rule
- I add a new rule "Zero Result"
- I edit the rule "Calc This"
1. I navigate to "Customize the System", expand the "Showcase" entity, and click Business Rules. Then I click New to create a new Business Rule
2. I name the second rule "Zero Result" and define one condition and two actions - if the two option field "DoTheMath" is set to "No" then set the value of the whole number field to 0 and hide the field
3. I edit the existing rule "Calc This" - adding one more action to ensure that the "Result" field is visible if "DoTheMath" = "Yes"
What I'm leveraging here is that if I add multiple business rules to an entity, the rules will run in the order they were added (the last modified business rule always runs last - not important in my scenario, though)
From now on, when I select "Yes" in "DoTheMath" the calculation will be performed, a result will be set in the "Result" field, and the "Result" field will be visible
On the other hand, if I select "No" in "DoTheMath" no calculation will be performed, the value zero (0) will be set in the "Result" field, and the "Result" field will be hidden
I welcome you to give our new Business Rules a try yourself - they are pretty powerful. As seen above you can easily create If-Then-Else logic using two or more rules.