Using Business Rule For Data Import Validation

Recently, I saw one question in a CRM forum where the user was interested in using Business Rules to implement data validation for Data Import. So can we do that? The answer is yes, of course we can do that, the business provides support to run your logic on the server side. If you don’t know about this, check our earlier article first, but from the end-user perspective, it will not be helpful.

Let’s see this in action using a quick business rule on Contact entity. Suppose we have a couple of fields which are required and we want to cancel data import if those sets of fields are missing an import file. Let’s say we want to enforce the user to supply contact’s email and phone number:

 

So let’s setup quick business rules for contact entity to show the error message if contact’s email or phone number is null.

If you are new to the business rule, please check our earlier articles

  1. Navigate to your Dynamics 365 customer engagement application or you can set up a trail, using our earlier article
  2. Create a custom solution and contact entity in our solution.
  3. Expand entity node under Components.
  4. Select Contact and select Business Rules under Contact entity node.
  5. Click on New under business rule toolbar to create a new business rule.
  6. Click on Add condition and add two rules, one for email and one for phone. We can use the or operator between them.
  7. Add Show Error Message action, to show the error message, write some message. After completion, it should look something like below:


  8. Now, make sure to set the scope of the business rule as Entity (Because we want to make sure this should run from server side call).


  9. Save and activate the business rule.

Now when we will import contact record, with a missing email or phone number, it will show us the error.


So, as you can see the message is not user-friendly so we should look for other options which can provide a more user-friendly message.