Business rules are great. Aren’t they? But how many implementations I have seen where customers initially were so much excited about no code development using business rules and finally they found that very simple stuffs cannot be achieved using Business Rules and finally they end up disappointed.
I faced a very similar situation recently. I had a requirement where I had to set a particular field value to something if a condition satisfies and clear it out if the condition does not satisfy. Well very simple requirement isn’t it. I suggested we use custom XRM scripts to do the same but client asked back with much surprise – Business Rule cannot do this? Considering my love for Dynamics CRM, I decided to give it a try.
To continue reading the post, you have to be aware that business rules are internally process records in CRM. If you are not aware of this, you should check out my other blog post –
https://debajmecrm.com/know-how-are-business-rules-created-as-process-records-in-crm/
In my example I created two Business Rules for my account entity
- If Address 1: City equals Bangalore, then populate “Account Number” field as “BNG001”
- If Address 1: City does not equal Bangalore, clear out “Account Number” field.
Not a very logical requirement but good for our demo. Check for the screenshots below:
In the rule “Address 1: City not equals Bangalore”, I have set Account Number to some “[PlaceHolder Text]”. Remember we are going to set is null. Since you cannot enter empty values here in UI, hence the place holder text. Don’t worry we are going to change it soon!
Now I activate both the rules and export the solution. Once exported I extract the solution. And this is what you find in the extracted solution.
Open the workflows folder and you can see your Business Rules
I open the Business Rule – “Address 1: City not equals Bangalore” and put the content in a XML editor. Once you do that, search for the keyword “SetAttributeValueStep”. Please check the screenshot below where you can see the placeholder text that we set before.
Replace the placeholder text with empty string and save the file.
Zip back the entire extracts of the solution so that it can be imported back.
Now once you import the solution back, you can see the change in effect.
Voila! you are there. One more thing, what does CRM return when you query the account number attribute using XRM script. Well lets see.
No problem. It returns null.
Hope you liked it.
Discover more from Debajit's Power Apps & Dynamics 365 Blog
Subscribe to get the latest posts sent to your email.
Good job with this Blog Post.
I had some free time today and exploring your blog was a pleasure. Please display a statutory Warnings as well – Unsupported Configurations should be implemented on developers own risk. 😀
Great job buddy.
Thanks!
And it was a pleasure as well working with you in Microsoft. Miss those days buddy
Good One Deb. 🙂
Thanks
good job that’s was a great trick
Hi Liberso,
Thanks!