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"
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.
Thanks for the quick response! In the case of calculated fields, this may fit the requirement (i.e. a "0" amount may or may not be viewed the same as a NULL field by the business users- depending on requirement). Basically "Set to Zero" != "Remove Value"
When it comes to Lookup Fields, this presents a bit of a problem. If I have a Custom Entity that has separate lookups to an Account or a Contact depending on the nature of the Record, and I want to force entry of that Lookup (set required, unlock, and show) and to force a NULL value of the other Lookup (hide, set not required, and lock), there is no clean way to clear the value of the second lookup before locking the field.
So if I start out with Record XYZ and Lookup 1 pointing to Contact A and I determine that the reference needs to be updated to use Lookup 2 pointing to Account B, Record XYZ retains the Lookup 1 reference to Contact A, even if I lock and hide the field. Because the usual business case would be to make these Searchable Fields, this causes messy data.
Does the SDK support Custom PBL Activities (similar to Custom Workflow Activities)? Clearing the value of a field would be at or near the top of my wishlist for extensibility of PBL.
Thanks again for your response.
By the way, I love PBL and if it were not for its incredibly intuitive interface, would not have already stretched it to the point of discovering its (current) boundaries.
Hi Joe, if you need more complex business rules functionality have a look at North52's Formula Manager product - it's very powerful! www.north52.com