Technology Blog Posts by Members
cancel
Showing results for 
Search instead for 
Did you mean: 

Introduction:

In this blog post, I will explain how we can utilize webhook from MS Dynamics CRM for case replication.

The following topics will be covered.

  • How to connect SAP Cloud Integration from Microsoft Dynamics using a Webhook
  • How to use Microsoft Dynamics CRM receiver adapter
  • How to use FetchXML query type for data retrieval
  • How to use ExternalID concept to match records between two systems

Scenario:

  1. Support executive can create a new case or update an existing case in the MS Dynamics system.
  2. The create/update event should trigger a notification to Cloud Integration.
  3. To mimic the target system, I am using just a dummy API which generates ID upon request.

Prerequisite Setup:

  1. Install Microsoft Dynamics CRM Adapter from the software center. 
  2. Install eclipse plugin for Microsoft Dynamics CRM (optional)

Configuration at MS Dynamics:

Please note, the below screenshots of Dynamics 365 are from a trial account.

1. Create an App: 

Go to https://portal.azure.com -> App registration

This will generate Application (client) ID. 

pic1.png

 Next, generate client id. Copy the value -> this is the client secret

pic2.png
pic3.png
Now, go to Manage -> API Permissions -> Click on ‘Add Permission’ -> select ‘Dynamics CRM’.
pic4.png
pic5.png
pic6.png
pic7.png

Now, open the eclipse plugin view to test the connection.

Window -> Preferences -> Select authentication type as ‘OAuth Client Credential Secret’.

pic8.png
2. Create an application user

Settings -> Security -> Application users

pic9.png

pic10.png

3. Create a custom field

Systems -> Customizations -> Customize the system -> Components -> Entities -> Case -> Fields 

pic11.png

pic12.png

4. Create webhook using Plugin Registration Tool

pic13.png

pic14.png

Endpoint URL is the endpoint exposed by the iflow.

Register new step

pic16.png

For create operation, webhook will trigger only if ‘productid’ is set for the case.

pic20.png

 For update operation, webhook will trigger only if ‘title’ is changed for the case.

Click on Update step -> Register New Image

pic18.png

Configuration at Cloud Integration:

Create Security Material

pic17.png

Design IFlow

Step 1

JSON to XML converter to convert incoming JSON payload to XML

Step 2

Router step to determine operation type

pic26.png

Step 3

Content Modifier step to extract required parameterspic22.png

For example:

Xpath for CaseOrigin

/root/InputParameters[key='Target']/value/FormattedValues[key='caseorigincode']/value

Xpath for ProductId

/root/InputParameters[key='Target']/value/Attributes[key='productid']/value/Id

Step 4

Receiver channel for MS Dynamics CRM to query linked entity using fetch xml

pic23.png

pic24.png

<fetch mapping= "logical"><entity name="incident"><!-- Filters --><filter><condition attribute="incidentid" operator="eq" value="${property.IncidentId}"/></filter><link-entity name="product" from="productid" to="productid" alias="product"><attribute name="name"/><attribute name="productnumber"/><filter><condition attribute="productid" operator="eq" value="${property.ProductId}"/><!-- Product ID --></filter></link-entity><!-- Fetch related Customer (Contact or Account) --><link-entity name="contact" from="contactid" to="customerid" alias="customer_contact" link-type="outer"><attribute name="fullname"/><attribute name="emailaddress1"/><attribute name="telephone1"/></link-entity><link-entity name="account" from="accountid" to="customerid" alias="customer_account" link-type="outer"><attribute name="name"/><!-- Account Name --><attribute name="emailaddress1"/><attribute name="telephone1"/></link-entity><link-entity name="systemuser" from="systemuserid" to="createdby" alias="createdby"><attribute name="fullname"/><filter><condition attribute="systemuserid" operator="eq" value="${property.InitiatingUserId}"/><!-- CreatedBy ID --></filter></link-entity><!-- Fetch related Business Unit --><link-entity name="businessunit" from="businessunitid" to="owningbusinessunit" alias="businessunit"><attribute name="name"/><filter><condition attribute="businessunitid" operator="eq" value="${property.BusinessUnitId}"/><!-- BusinessUnit ID --></filter></link-entity><link-entity name="subject" from="subjectid" to="subjectid" alias="subject"><attribute name="title"/><filter><condition attribute="subjectid" operator="eq" value="${property.SubjectId}"/><!-- Subject ID --></filter></link-entity></entity></fetch>

link-entity is used when you need to join related tables (or entities), similar to SQL JOINs.

<link-entity name="account" from="accountid" to="customerid" alias="customer_account" link-type="outer" />

name="account"

  • This specifies the related entity Account

from="accountid"

  • Primary key of the Account entity

to="customerid"

  • This refers to the foreign key in the base entity incident

alias="customer_account"

  • This provides an alias for the joined table. It's useful when referencing attributes from the linked entity in the results.

link-type="outer"

  • This defines the type of join:
    • inner (default): Only returns records where there's a match in both tables.
    • outer: Returns all records from the primary entity, even if there’s no matching record in the linked entity (similar to a LEFT JOIN in SQL).

Step 5

Content Modifier to set target payload for create operation

pic25.png

Step 6

Post call to dummy API

pic27.png

Step 7

Groovy script to modify response body

Step 8

Content modifier to set payload for patch requestpic28.png

Step 9

Receiver channel for MS Dynamics CRM to update custom field new_externalidpic29.png

Step 10

Content modifier to extract parameters for Update case

pic30.png

For example: Xpath for ExternalID

/root/PostEntityImages[key='incident']/value/Attributes[key='new_externalid']/value

pic31.png

Step 11

Patch call to Dummy API

 

Reference Links:

1. Dynamics 365 Webhook

2. Microsoft Dynamics CRM Adapter

Regards,

Priyanka Chakraborti

1 Comment
Labels in this area