Introduction:
In this blog post, I will explain how we can utilize webhook from MS Dynamics CRM for case replication.
Scenario:
Support executive can create a new case or update an existing case in the MS Dynamics system.The create/update event should trigger a notification to CPI.To mimic the target system, I am using just a dummy API which generates ID upon request.
Prerequisite Setup:
Install Microsoft Dynamics CRM Adapter from the software center. 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.
Next, generate client id. Copy the value -> this is the client secret
Now, open the eclipse plugin view to test the connection.
Window -> Preferences -> Select authentication type as ‘OAuth Client Credential Secret’.
2. Create an application user
Settings -> Security -> Application users
3. Create a custom field
Systems -> Customizations -> Customize the system -> Components -> Entities -> Case -> Fields
4. Create webhook using Plugin Registration Tool
Endpoint URL is the endpoint exposed by the iflow.
Register new step
For create operation, webhook will trigger only if ‘productid’ is set for the case.
For update operation, webhook will trigger only if ‘title’ is changed for the case.
Click on Update step -> Register New Image
Configuration at Cloud Integration:
Create Security Material
Design IFlow
Step 1
JSON to XML converter to convert incoming JSON payload to XML
Step 2
Router step to determine operation type
Step 3
Content Modifier step to extract required parameters
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
<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
Step 6
Post call to dummy API
Step 7
Groovy script to modify response body
Step 8
Content modifier to set payload for patch request
Step 9
Receiver channel for MS Dynamics CRM to update custom field new_externalid
Step 10
Content modifier to extract parameters for Update case
For example: Xpath for ExternalID
/root/PostEntityImages[key=’incident’]/value/Attributes[key=’new_externalid’]/value
Step 11
Patch call to Dummy API
Reference Links:
2. Microsoft Dynamics CRM Adapter
Regards,
Priyanka Chakraborti
Introduction:In this blog post, I will explain how we can utilize webhook from MS Dynamics CRM for case replication.Scenario:Support executive can create a new case or update an existing case in the MS Dynamics system.The create/update event should trigger a notification to CPI.To mimic the target system, I am using just a dummy API which generates ID upon request.Prerequisite Setup:Install Microsoft Dynamics CRM Adapter from the software center. 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 registrationThis will generate Application (client) ID. Next, generate client id. Copy the value -> this is the client secretNow, go to Manage -> API Permissions -> Click on ‘Add Permission’ -> select ‘Dynamics CRM’.Now, open the eclipse plugin view to test the connection.Window -> Preferences -> Select authentication type as ‘OAuth Client Credential Secret’.2. Create an application userSettings -> Security -> Application users3. Create a custom fieldSystems -> Customizations -> Customize the system -> Components -> Entities -> Case -> Fields 4. Create webhook using Plugin Registration ToolEndpoint URL is the endpoint exposed by the iflow.Register new stepFor create operation, webhook will trigger only if ‘productid’ is set for the case. For update operation, webhook will trigger only if ‘title’ is changed for the case.Click on Update step -> Register New ImageConfiguration at Cloud Integration:Create Security MaterialDesign IFlowStep 1JSON to XML converter to convert incoming JSON payload to XMLStep 2Router step to determine operation typeStep 3Content Modifier step to extract required parametersFor example:Xpath for CaseOrigin/root/InputParameters[key=’Target’]/value/FormattedValues[key=’caseorigincode’]/valueXpath for ProductId/root/InputParameters[key=’Target’]/value/Attributes[key=’productid’]/value/IdStep 4Receiver channel for MS Dynamics CRM to query linked entity using fetch xml<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 Accountfrom=”accountid”Primary key of the Account entityto=”customerid”This refers to the foreign key in the base entity incidentalias=”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 5Content Modifier to set target payload for create operationStep 6Post call to dummy APIStep 7Groovy script to modify response bodyStep 8Content modifier to set payload for patch requestStep 9Receiver channel for MS Dynamics CRM to update custom field new_externalidStep 10Content modifier to extract parameters for Update caseFor example: Xpath for ExternalID/root/PostEntityImages[key=’incident’]/value/Attributes[key=’new_externalid’]/valueStep 11Patch call to Dummy API Reference Links:1. Dynamics 365 Webhook2. Microsoft Dynamics CRM AdapterRegards,Priyanka Chakraborti Read More Technology Blogs by Members articles
#SAP
#SAPTechnologyblog