Clear out field value using Dynamics CRM 2013 Business Rules? Yes you can!

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://debajitcrm.wordpress.com/2014/12/19/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:

image

 

image

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.

image

 

Open the workflows folder and you can see your Business Rules

image

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.

image

Replace the placeholder text with empty string and save the file.

image

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.

image

image

Voila! you are there. One more thing, what does CRM return when you query the account number attribute using XRM script. Well lets see.

image

 

No problem. It returns null.

Hope you liked it.

Advertisements

Author: Debajit

I am a Dynamics CRM Most Valuable Professional (MVP) with 10 years of experience in Microsoft .NET Technologies and 7 years of dedicated experience in Microsoft Dynamics CRM. I have worked with companies like Microsoft, SanDisk, PwC, TMF Group and have extensive experience of implementing complex CRM solutions from both offshore and client side. Currently the face of XrmForYou.com with significant experience in delivering corporate training on Dynamics CRM and have already delivered multiple projects to client through XrmForYou.com Author of multiple tools on codeplex including the 'Role Based Views' and 'CRM-Sharepoint Metadata manager & Attachment Extractor' which are available for commercial use under XrmForYou.com For consulting/ training, drop me a note at info@xrmforyou.com or visit our website www.xrmforyou.com

6 thoughts on “Clear out field value using Dynamics CRM 2013 Business Rules? Yes you can!”

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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s