Business Rules With Scope Entity And Server-Side Execution

Introduction

In Dynamics 365 CRM or Power Platform, updates in entity data using service call /SDK will makechanges in the server-side, then server-side business rules will fire i.e., business rules with scope Entity will fire. As a business scenario, we are going to see updates in contact entity by invoking service call through Postman Tool which invokes business rule with Entity Scope.

Step 1

Login to the required Dynamics CRM/ Power Apps environment using URL make.powerapps.com by providing username and password and go to solutions as shown in the below figure.

Business Rules with Scope Entity and Server-Side Execution

Step 2

After step 1, select ContactCustomizations custom solution as shown in the below figure.

Business Rules with Scope Entity and Server-Side Execution

Step 3

After step 2, in the ContactCustomizations custom solution open Contact Entity and then click on the Business Rules tab, and then Click on Add business rule as shown in the below figure.

Business Rules with Scope Entity and Server-Side Execution

Step 4

After step 3, create a business rule with scope as Entity and name business rule with Show Business Required Fields in Contact And Set Visibility. The logic here is if the field Birthday has value, then field Vaccination becomes mandatory and the Discount field will be shown. Save the business rule and activate and then publish the solution as shown in the below figure.

Business Rules with Scope Entity and Server-Side Execution

Step 5

After step 4, create a record in contact entity in selected Dynamics CRM Environment with a service call using Post Man tool and prepare request JSON as per the below format,

{
 "firstname": "James",
 "lastname": "M"
}

And once JSON is prepared, in the Post Man tool open a new request tab and provide required authentication related to CRM Environment. Paste above JSON in request body with the selection of raw and format as JSON as shown in the below figure,

Business Rules with Scope Entity and Server-Side Execution

Step 6

After step 5, before the creation of the record, open the respective CRM Environment and verify the contact is not present in the list of contacts as shown in the below figure.

Business Rules with Scope Entity and Server-Side Execution

Step 7

After step 6, go to step 5 and click on Send Button and once you receive a response then a record gets created in the CRM Environment as shown in the below figure,

Business Rules with Scope Entity and Server-Side Execution

Step 8

After step 7, go to the CRM environment and select contact entity, and see the results. You should see a newly created record with the name James M as shown in the below figure.

Business Rules with Scope Entity and Server-Side Execution

Step 9

After step 8, open the newly created James M record and see Discount field not populated and Vaccination field is not required as shown in the below figure,

Business Rules with Scope Entity and Server-Side Execution

Step 10

After step 9, copy the record id of the James M contact record so that we can update this record using Post Man tool by providing Birthdate as shown in the below figure,

Business Rules with Scope Entity and Server-Side Execution

Step 11

After step 10, open the Post Man tool and prepare a new request to update contact record with a field using Patch Verb and prepare a request with respective JSON body for Birthday field using the below JSON,

{
 "birthdate": "2000-07-01"
}

 and click on Send button if everything works fine then the record gets updated as shown in the below figure,

Business Rules with Scope Entity and Server-Side Execution

Step 12

After step 11, navigate back to CRM environment and open/ refresh James M record and see birthdate got populated and the respective business rule was created in Step 4 fires and makes fields Vaccination as Business Required and Discount Field shows up in the form as shown in the below figure,

Business Rules with Scope Entity and Server-Side Execution

Note

  1. Please make sure you keep the required fields on Contact Form.
  2. Select fields for Actions as well as for Conditions without fail.
  3. Make sure to Activate Business Rule after save and give scope as.
  4. Publish all changes without fail.
  5. Give the name of conditions and Actions names in a meaningful way.
  6. Make sure to configure CRM Environment in Post Man tool to use for Create and Update operations.
  7. Take proper care to see JSON was well-formed or not.

Conclusion

In this way any server-side operations happen in CRM, respective business rules with scope Entity gets fired.