Enable Javascript

Please enable Javascript to view website properly

Toll Free 1800 889 7020

Looking for an Expert Development Team? Take 2 weeks Free Trial! Try Now

Validate CRM field data using Azure Logic-Apps Inline JavaScript

Description

Recently Microsoft introduced a provision for Azure Logic-Apps wherein the developers can add a built-in Inline JavaScript code action as a step in our Logic-App’s workflow. This action runs the code snippet and returns its output as a token named Result.

In this blog, we will try to create a D365 CE Contact record from a JSON message passed from Service Bus Explorer via a Logic-App.

We will first add a new CE Contact text field called PAN that accepts a Permanent Account Number (Indian Format). In Logic-App, we aim to use the Inline JS action to validate PAN against Reg-Ex expressions and create CE contact records only if they are in the correct format.

Steps

1. Login to D365 CE and create a new text field – PAN (Permanent Account Number) for the Contact entity. Place it on the main form. Save and Publish.

CRM field data 1
CRM field data 2

2. Create a new Azure Logic-App with the Trigger – “When a message is received in a Service Bus queue”.

CRM field data 3

3. Establish the connection to your Service-Bus and specify the queue name.

CRM field data 4
CRM field data 5

4. Add the next action in the Logic-App – Parse JSON. Set the *Content to json(decodeBase64(triggerBody()[‘ContentData’])). Set the schema as follows.

{ "properties": { "PAN": { "type": "string" }, "businessPhone": { "type": "string" }, "city": { "type": "string" }, "email": { "type": "string" }, "firstname": { "type": "string" }, "lastname": { "type": "string" } }, "type": "object" }
CRM field data 6

5. Next, add the action – Execute JavaScript Code. NOTE – Make sure an Integration Account is linked to your Azure Logic App. For more information - https://docs.microsoft.com/en-us/azure/logic-apps/logic-apps-add-run-inline-code.

CRM field data 7

6. Add the following code to this Action.

var receivedPan = workflowContext.actions.Parse_JSON.outputs.body.PAN; var panPattern = /^[A-Z]{5}[0-9]{4}[A-Z]{1}$/; //RegEx for a PAN (example: DDDPP5678K) return panPattern.test(receivedPan)
CRM field data 8

7. After it, add a new condition to check the Result of the above action. If it is False, Terminate the Logic-App with the Message – “PAN is in the incorrect format”. If the Result is True, create a new CE

CRM field data 9

8. Map the fields from the output of the “Parse JSON” action to the Dynamics 365 CE contact. Save all these changes.

CRM field data 10

Unit-Testing

We move to the Service Bus Explorer and send the following JSON message with PAN in the correct format.

CRM field data 11

We verify that the Logic-App has run correctly, and the CE Contact record is created as expected.

CRM field data 12
CRM field data 13

We now send a JSON message with an incorrect PAN and verify that the Logic-App is terminated with the expected message.

CRM field data 14
CRM field data 15

Conclusion

In this blog, Dynamics CRM Consultants describe step by step how we can use inline JS code action in logic applications to validate the D365 CE field.

We hope this will be helpful.

Software Development Team
Need Software Development Team?
captcha
🙌

Thank you!
We will contact soon.

Oops! Something went wrong.

Recent Blogs

Categories

NSS Note
Trusted by Global Clients