Contact Free trial Login

Microsoft Dynamics CRM Connector - Mule 4

Support Category: Select

Microsoft Dynamics CRM v3.2

Anypoint Connector for Microsoft Dynamics CRM allows Mule appns to interact with Microsoft Dynamics CRM’s SOAP Organization Service.

Read through this user guide to understand how to set up and configure a basic flow using the connector. Track feature additions, compatibility, limitations, and API version updates using the Release Notes.

Prerequisites

To use this information, you should be familiar with Microsoft Dynamics CRM, Mule, Anypoint Connectors, Anypoint Studio, Mule concepts, elements in a Mule flow, and Global Elements.

You need login credentials to test your connection to your target resource.

For software requirements and compatibility information, see the Connector Release Notes.

POM File Information

<dependency>
  <groupId>com.mulesoft.connectors</groupId>
  <artifactId>mule-microsoft-dynamics-crm-connector</artifactId>
  <version>RELEASE</version>
  <classifier>mule-plugin</classifier>
</dependency>

Mule converts RELEASE to the latest version. To specify a version, view Microsoft Dynamics CRM Connector in Anypoint Exchange and click Dependency Snippets.

Connect in Design Center

  1. In Design Center, click a trigger such as an HTTP Listener or Scheduler trigger.

  2. To create an optional global element, click Reusable Configurations, and configure the following options:

    • Username: Enter the Dynamics CRM username.

    • Password: Enter the corresponding password.

    • Organization Service URL: Enter the corresponding organization service URL.

    • Authentication retries: Enter the desired number of retries for authentication.

    • Disable cn check: Choose if you want to bypass SSL Certificates.

      Design Center Global Element General tab
  3. Select the plus sign to add a component.

  4. Select the connector as a component.

  5. Configure these fields:

    Create:

    • Logical Name - The logical name of the entity

    • Attributes - The attributes of the record as a Map<String, Object>.

      Design Center Create configuration

      Update:

    • Logical Name - The logical name of the entity.

    • Id* - The ID of the record to update..

    • Attributes - The attributes to be updated as a Map<String, Object>.

      Design Center Update configuration

      Delete:

    • Logical Name - The logical name of the entity.

    • Id - The ID of the record to delete.

      Design Center Delete configuration

      Retrieve:

      • Logical Name - The logical name of the entity.

      • Id - The ID of the record to retrieve.

      • Attributes - The attributes of the specified entity as a Map<String, Object>.

        Design Center Retrieve configuration

        Retrieve Multiple By Query:

    • Query - For DataSense Query Language, the DSQL query. For Native Query Language, the Fetch XML query.

    • Items Per Page - The number of items returned per page.

    • Single Page Number - If greater than 0, returns only that specific page.

      Design Center Retrieve Multiple configuration

      Associate:

    • Logical Name - The logical name of the entity.

    • Id*- The ID of the record to which the related records are associated.

    • Relationship Entity Role Is Referenced:

      • false: When the primary entity record is Referencing the record to associate.

      • true: When the primary entity record is Referenced by the record to associate.

        Design Center Associate configuration

        Execute:

    • Request Name - The logical name of request to make.

    • Request Parameters - [DEPRECATED] This parameter will be removed from the configuration in the near future. Set the #[payload] correctly before calling the connector.

    • Request Id - The ID of the request to make.

      Design Center Execute configuration

Add the Connector to a Studio Project

Anypoint Studio provides two ways to add the connector to your Studio project: from the Exchange button in the Studio taskbar or from the Mule Palette view.

Add the Connector Using Exchange

  1. In Studio, create a Mule project.

  2. Click the Exchange icon (X) in the upper-left of the Studio task bar.

  3. In Exchange, click Login and supply your Anypoint Platform username and password.

  4. In Exchange, search for "crm".

  5. Select the connector and click Add to project.

  6. Follow the prompts to install the connector.

Add the Connector in Studio

  1. In Studio, create a Mule project.

  2. In the Mule Palette view, click (X) Search in Exchange.

  3. In Add Modules to Project, type "crm" in the search field.

  4. Click this connector’s name in Available modules.

  5. Click Add.

  6. Click Finish.

Configure in Studio

  1. Drag the connector to the Studio Canvas.

  2. To create a global element for the connector, set these fields:

    Online Authentication (Default):

    • Username: Enter the Dynamics CRM username.

    • Password: Enter the corresponding password.

    • Organization Service URL: Enter the corresponding organization service URL.

    • Authentication retries: Enter the desired number of retries for authentication.

    • Disable cn check: Choose if you want to bypass SSL Certificates.

      Credentials configuration

Use Case - Microsoft Dynamics CRM Operations Demo

This demo includes the following options:

  • Return all accounts: http://localhost:8081/accounts

  • Query accounts by name containing a substring: http://localhost:8081/query-accounts?name=li

  • Create a new account with the specified name: http://localhost:8081/create-account?name=your-account-name

  • Retrieve account by ID: http://localhost:8081/retrieve-account?accountid={account-guid}

  • Delete an account: http://localhost:8081/delete-account?accountid={account-guid}

  • Return all contacts: http://localhost:8081/contacts

  • Return all contacts for an account: http://localhost:8081/contacts-by-account?accountid={account-guid}

  • Associate a contact to an account: http://localhost:8081/associate?accountid={account-guid}&contactid={contact-guid}

  • Disassociate a contact from an account: http://localhost:8081/disassociate?accountid={account-guid}&contactid={contact-guid}

  • Create an opportunity: http://localhost:8081/create-opportunity?accountid={account-guid}&contactid={contact-guid}

  • Query opportunities by parent account: http://localhost:8081/opportunities-by-account?accountid={account-guid}

  • Activate an account by executing the SetState operation: http://localhost:8081/activate-account?accountid={account-guid}

  • Deactivate an account by executing the SetState operation: http://localhost:8081/deactivate-account?accountid={account-guid}

  • Create multiple entities in a single request: http://localhost:8081/create-multiple

  • Update the property 'Description' of multiple contacts in a single request: http://localhost:8081/update-multiple

  • Retrieve updated contacts: http://localhost:8081/updated-contacts

  • Delete multiple contacts in a single request: http://localhost:8081/delete-multiple

Use Case Studio Visual Flow

ms dynamics crm demo 01
ms dynamics crm demo 02
ms dynamics crm demo 03
ms dynamics crm demo 04
ms dynamics crm demo 05

Use Case XML Flow

<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core"
    xmlns:microsoft-dynamics-crm="http://www.mulesoft.org/schema/mule/microsoft-dynamics-crm"
    xmlns:http="http://www.mulesoft.org/schema/mule/http"
    xmlns="http://www.mulesoft.org/schema/mule/core"
    xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core
    http://www.mulesoft.org/schema/mule/core/current/mule.xsd
    http://www.mulesoft.org/schema/mule/http
    http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
    http://www.mulesoft.org/schema/mule/microsoft-dynamics-crm
    http://www.mulesoft.org/schema/mule/microsoft-dynamics-crm/current/mule-microsoft-dynamics-crm.xsd
    http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd">
    <configuration-properties file="mule-app.properties"/>

    <http:listener-config
        name="HTTP_Listener_config"
        doc:name="HTTP Listener config" >
        <http:listener-connection
        host="localhost"
        port="8081" />
    </http:listener-config>
    <microsoft-dynamics-crm:dynamics-crm-config
        name="Microsoft_Dynamics_CRM_Dynamics_CRM"
        doc:name="Microsoft Dynamics CRM Dynamics CRM" >
        <microsoft-dynamics-crm:online-connection
            username="${username}"
            password="${password}"
            organizationServiceUrl="${organizationServiceUrl}"
            authenticationRetries="${authenticationRetries}" />
    </microsoft-dynamics-crm:dynamics-crm-config>
    <flow name="crm-all-accounts"  >
        <http:listener
            doc:name="Listener"
            config-ref="HTTP_Listener_config"
            path="/accounts"/>
        <microsoft-dynamics-crm:retrieve-multiple-by-query
            doc:name="Retrieve multiple by query"
            config-ref="Microsoft_Dynamics_CRM_Dynamics_CRM">
            <microsoft-dynamics-crm:query ><![CDATA[dsql:SELECT accountid,name,statecode,statuscode FROM account]]></microsoft-dynamics-crm:query>
        </microsoft-dynamics-crm:retrieve-multiple-by-query>
        <ee:transform doc:name="Transform Message" >
            <ee:message >
                <ee:set-payload ><![CDATA[%dw 2.0
output application/json
---
payload]]></ee:set-payload>
            </ee:message>
        </ee:transform>
    </flow>
    <flow name="crm-query-account-by-name"  >
        <http:listener
            doc:name="Listener"
            config-ref="HTTP_Listener_config"
            path="/query-accounts"/>
        <ee:transform doc:name="Transform Message" >
            <ee:message >
                <ee:set-payload ><![CDATA[%dw 2.0
output application/json
---
{
    "query" : "dsql:SELECT accountid,name,statecode,statuscode FROM account WHERE name LIKE '%" ++ attributes.queryParams.name ++ "%'"
}]]></ee:set-payload>
            </ee:message>
        </ee:transform>
        <microsoft-dynamics-crm:retrieve-multiple-by-query
            doc:name="Retrieve multiple by query"
            config-ref="Microsoft_Dynamics_CRM_Dynamics_CRM">
            <microsoft-dynamics-crm:query ><![CDATA[#[payload.query]]]></microsoft-dynamics-crm:query>
        </microsoft-dynamics-crm:retrieve-multiple-by-query>
        <ee:transform doc:name="Transform Message" >
            <ee:message >
                <ee:set-payload ><![CDATA[%dw 2.0
output application/json
---
payload]]></ee:set-payload>
            </ee:message>
        </ee:transform>
    </flow>
    <flow name="crm-create-account" >
        <http:listener
            doc:name="Listener"
            config-ref="HTTP_Listener_config"
            path="/create-account"/>
        <ee:transform doc:name="Transform Message"  >
            <ee:message >
                <ee:set-payload ><![CDATA[%dw 2.0
output application/json
---
{
    "name": attributes.queryParams.name
}]]></ee:set-payload>
            </ee:message>
        </ee:transform>
        <microsoft-dynamics-crm:create
            logicalName="account"
            doc:name="Create"
            config-ref="Microsoft_Dynamics_CRM_Dynamics_CRM"/>
        <ee:transform doc:name="Transform Message" >
            <ee:message >
                <ee:set-payload ><![CDATA[%dw 2.0
output application/json
---
payload]]></ee:set-payload>
            </ee:message>
        </ee:transform>
    </flow>
    <flow name="crm-delete-account"
        config-ref="HTTP_Listener_config"
        path="/delete-account"/>
        <microsoft-dynamics-crm:delete
            logicalName="account"
            id="#[attributes.queryParams.accountid]"
            doc:name="Delete"
            config-ref="Microsoft_Dynamics_CRM_Dynamics_CRM" />
    </flow>
    <flow name="crm-retrieve-account" >
        <http:listener
            doc:name="Listener"
            config-ref="HTTP_Listener_config"
            path="/retrieve-account"/>
        <microsoft-dynamics-crm:retrieve
            logicalName="account"
            id="#[attributes.queryParams.accountid]"
            doc:name="Retrieve"
            config-ref="Microsoft_Dynamics_CRM_Dynamics_CRM" />
        <ee:transform doc:name="Transform Message" >
            <ee:message >
                <ee:set-payload ><![CDATA[%dw 2.0
output application/json
---
payload]]></ee:set-payload>
            </ee:message>
        </ee:transform>
    </flow>
    <flow name="crm-all-contacts" >
        <http:listener
            doc:name="Listener"
            config-ref="HTTP_Listener_config"
            path="/contacts"/>
        <microsoft-dynamics-crm:retrieve-multiple-by-query
            doc:name="Retrieve multiple by query"
            config-ref="Microsoft_Dynamics_CRM_Dynamics_CRM">
            <microsoft-dynamics-crm:query ><![CDATA[dsql:SELECT accountid,contactid,firstname,lastname FROM contact]]></microsoft-dynamics-crm:query>
        </microsoft-dynamics-crm:retrieve-multiple-by-query>
        <ee:transform doc:name="Transform Message" >
            <ee:message >
                <ee:set-payload ><![CDATA[%dw 2.0
output application/json
---
payload]]></ee:set-payload>
            </ee:message>
        </ee:transform>
    </flow>
    <flow name="crm-get-associated-contacts" >
        <http:listener doc:name="Listener"
            config-ref="HTTP_Listener_config"
            path="/contacts-by-account"/>
        <ee:transform doc:name="Transform Message" >
            <ee:message >
                <ee:set-payload ><![CDATA[%dw 2.0
output application/json
---
{
    "query" : "dsql:SELECT contactid, accountidname, parentcustomerid_referenceto_account FROM contact WHERE parentcustomerid_referenceto_account = '" ++ attributes.queryParams.accountid ++ "'"
}]]></ee:set-payload>
            </ee:message>
        </ee:transform>
            doc:name="Retrieve multiple by query"
            config-ref="Microsoft_Dynamics_CRM_Dynamics_CRM">
            <microsoft-dynamics-crm:query ><![CDATA[#[payload.query]]]></microsoft-dynamics-crm:query>
        </microsoft-dynamics-crm:retrieve-multiple-by-query>
        <ee:transform doc:name="Transform Message" >
            <ee:message >
                <ee:set-payload ><![CDATA[%dw 2.0
output application/json
---
payload]]></ee:set-payload>
            </ee:message>
        </ee:transform>
    </flow>
    <flow name="crm-associate-contact-to-account" >
        <http:listener
            doc:name="Listener"
            config-ref="HTTP_Listener_config"
            path="/associate"/>
        <ee:transform doc:name="Transform Message" >
            <ee:message >
                <ee:set-payload ><![CDATA[%dw 2.0
output application/java
---
[
    attributes.queryParams.contactid
]]]></ee:set-payload>
            </ee:message>
        </ee:transform>
        <microsoft-dynamics-crm:associate
            logicalName="account"
            relatedEntitiesIds="#[payload]"
            doc:name="Associate"
            config-ref="Microsoft_Dynamics_CRM_Dynamics_CRM"
            relationshipSchemaName="contact_customer_accounts"
            id="#[attributes.queryParams.accountid]"
            relationshipEntityRoleIsReferenced="true"/>
    </flow>
    <flow name="crm-disassociate-contact-to-account" >
        <http:listener doc:name="Listener"
            config-ref="HTTP_Listener_config"
            path="/disassociate"/>
        <ee:transform doc:name="Transform Message" >
            <ee:message >
                <ee:set-payload ><![CDATA[%dw 2.0
output application/java
---
[
    attributes.queryParams.contactid
]]]></ee:set-payload>
            </ee:message>
        </ee:transform>
        <microsoft-dynamics-crm:disassociate
            doc:name="Disassociate"
            config-ref="Microsoft_Dynamics_CRM_Dynamics_CRM"
            logicalName="account"
            id="#[attributes.queryParams.accountid]"
            relationshipEntityRoleIsReferenced="true"
            relationshipSchemaName="contact_customer_accounts"
            relatedEntitiesIds="#[payload]"/>
    </flow>
    <flow name="crm-get-opportunities" >
        <http:listener doc:name="Listener"
            config-ref="HTTP_Listener_config"
            path="/opportunities-by-account"/>
        <ee:transform doc:name="Transform Message" >
            <ee:message >
                <ee:set-payload ><![CDATA[%dw 2.0
output application/json
---
{
    "query" : "dsql:SELECT accountid_referenceto_account,accountidname,customerid_referenceto_contact,name,parentaccountid_referenceto_account FROM opportunity WHERE parentaccountid_referenceto_account = '" ++ attributes.queryParams.accountid ++ "'"
}]]></ee:set-payload>
            </ee:message>
        </ee:transform>
        <microsoft-dynamics-crm:retrieve-multiple-by-query
            doc:name="Retrieve multiple by query"
            config-ref="Microsoft_Dynamics_CRM_Dynamics_CRM">
            <microsoft-dynamics-crm:query ><![CDATA[#[payload.query]]]></microsoft-dynamics-crm:query>
        </microsoft-dynamics-crm:retrieve-multiple-by-query>
        <ee:transform doc:name="Transform Message" >
            <ee:message >
                <ee:set-payload ><![CDATA[%dw 2.0
output application/json
---
payload]]></ee:set-payload>
            </ee:message>
        </ee:transform>
    </flow>
    <flow name="crm-create-opportunity" >
        <http:listener
            doc:name="Listener"
            config-ref="HTTP_Listener_config"
            path="/create-opportunity"/>
        <ee:transform doc:name="Transform Message" >
            <ee:message >
                <ee:set-payload ><![CDATA[%dw 2.0
output application/json
---
{
    "parentaccountid_referenceto_account": attributes.queryParams.accountid,
    "contactid_referenceto_contact": attributes.queryParams.contactid,
    "name": "unique opportunity",
    "timeline": 2
}]]></ee:set-payload>
            </ee:message>
        </ee:transform>
        <microsoft-dynamics-crm:create
            logicalName="opportunity"
            doc:name="Create"
            config-ref="Microsoft_Dynamics_CRM_Dynamics_CRM"/>
        <ee:transform doc:name="Transform Message" >
            <ee:message >
                <ee:set-payload ><![CDATA[%dw 2.0
output application/json
---
payload]]></ee:set-payload>
            </ee:message>
        </ee:transform>
    </flow>
    <flow name="crm-execute-activate-account" >
        <http:listener
            doc:name="Listener"
            config-ref="HTTP_Listener_config"
            path="/activate-account"/>
        <ee:transform doc:name="Transform Message" >
            <ee:message >
                <ee:set-payload ><![CDATA[%dw 2.0
output application/java
---
{
    "entityMoniker": {
        "id": {
            "value": attributes.queryParams.accountid,
        },
        "logicalName": "account"
    },
    "state": {
        "value": 0
    },
    "status": {
        "value": 1
    }
}]]></ee:set-payload>
            </ee:message>
        </ee:transform>
        <microsoft-dynamics-crm:execute
            requestName="SetState" doc:name="Execute"
            config-ref="Microsoft_Dynamics_CRM_Dynamics_CRM"/>
        <ee:transform doc:name="Transform Message" >
            <ee:message >
                <ee:set-payload ><![CDATA[%dw 2.0
output application/json
---
payload]]></ee:set-payload>
            </ee:message>
        </ee:transform>
    </flow>
    <flow name="crm-execute-deactivate-account" >
        <http:listener
            doc:name="Listener"
            config-ref="HTTP_Listener_config"
            path="/deactivate-account"/>
        <ee:transform doc:name="Transform Message" >
            <ee:message >
                <ee:set-payload ><![CDATA[%dw 2.0
output application/java
---
{
    "entityMoniker": {
        "id": {
            "value": attributes.queryParams.accountid,
        },
        "logicalName": "account"
    },
    "state": {
        "value": 1
    },
    "status": {
        "value": 2
    }
}]]></ee:set-payload>
            </ee:message>
        </ee:transform>
        <microsoft-dynamics-crm:execute
            doc:name="Execute"
            config-ref="Microsoft_Dynamics_CRM_Dynamics_CRM"
            requestName="SetState"/>
        <ee:transform doc:name="Transform Message" >
            <ee:message >
                <ee:set-payload ><![CDATA[%dw 2.0
output application/json
---
payload]]></ee:set-payload>
            </ee:message>
        </ee:transform>
    </flow>
    <flow name="crm-create-multiple-contacts" >
        <http:listener
            doc:name="Listener"
            config-ref="HTTP_Listener_config"
            path="/create-multiple"/>
        <ee:transform doc:name="Transform Message" >
            <ee:message >
                <ee:set-payload ><![CDATA[%dw 2.0
output application/json
---
[
    {
      "fullname":"Contact1",
      "address1_city":"DemoCity",
      "description":"Demo contact 1"
    },
    {
      "fullname":"Contact2",
      "address1_city":"DemoCity",
      "description":"Demo contact 2"
    },
    {
      "fullname":"Contact3",
      "address1_city":"DemoCity",
      "description":"Demo contact 3"
    }
]]]></ee:set-payload>
            </ee:message>
        </ee:transform>
        <microsoft-dynamics-crm:create-multiple
            logicalName="contact"
            doc:name="Create multiple"
            config-ref="Microsoft_Dynamics_CRM_Dynamics_CRM"/>
        <ee:transform doc:name="Transform Message" >
            <ee:message >
                <ee:set-payload ><![CDATA[%dw 2.0
output application/json
---
payload]]></ee:set-payload>
            </ee:message>
        </ee:transform>
    </flow>
    <flow name="crm-delete-multiple" >
        <http:listener
            doc:name="Listener"
            config-ref="HTTP_Listener_config"
            path="/delete-multiple"/>
        <microsoft-dynamics-crm:retrieve-multiple-by-query
            doc:name="Retrieve multiple by query"
            config-ref="Microsoft_Dynamics_CRM_Dynamics_CRM">
            <microsoft-dynamics-crm:query ><![CDATA[dsql:SELECT contactid FROM contact WHERE address1_city = 'DemoCity']]></microsoft-dynamics-crm:query>
        </microsoft-dynamics-crm:retrieve-multiple-by-query>
        <ee:transform doc:name="Transform Message" >
            <ee:message >
                <ee:set-payload ><![CDATA[%dw 2.0
output application/java
---
payload.*contactid
]]></ee:set-payload>
            </ee:message>
        </ee:transform>
        <microsoft-dynamics-crm:delete-multiple
            logicalName="contact"
            ids="#[payload]"
            doc:name="Delete multiple"
            config-ref="Microsoft_Dynamics_CRM_Dynamics_CRM"/>
        <ee:transform doc:name="Transform Message" >
            <ee:message >
                <ee:set-payload ><![CDATA[%dw 2.0
output application/json
---
payload]]></ee:set-payload>
            </ee:message>
        </ee:transform>
    </flow>
    <flow name="crm-update-multiple-contacts" >
        <http:listener
            doc:name="Listener"
            config-ref="HTTP_Listener_config"
            path="/update-multiple"/>
        <microsoft-dynamics-crm:retrieve-multiple-by-query
            doc:name="Retrieve multiple by query"
            config-ref="Microsoft_Dynamics_CRM_Dynamics_CRM">
            <microsoft-dynamics-crm:query ><![CDATA[dsql:SELECT contactid,description FROM contact WHERE address1_city = 'DemoCity']]></microsoft-dynamics-crm:query>
        </microsoft-dynamics-crm:retrieve-multiple-by-query>
        <ee:transform doc:name="Transform Message" >
            <ee:message >
                <ee:set-payload ><![CDATA[%dw 2.0
output application/java
---
updates: payload map (item, index) -> {
      "contactid" : item.contactid,
      "description" : "Updated Description"
}]]></ee:set-payload>
            </ee:message>
        </ee:transform>
        <microsoft-dynamics-crm:update-multiple
            logicalName="contact"
            doc:name="Update multiple"
            config-ref="Microsoft_Dynamics_CRM_Dynamics_CRM">
            <microsoft-dynamics-crm:list-of-attributes ><![CDATA[#[payload.updates]]]></microsoft-dynamics-crm:list-of-attributes>
        </microsoft-dynamics-crm:update-multiple>
        <ee:transform doc:name="Transform Message" >
            <ee:message >
                <ee:set-payload ><![CDATA[%dw 2.0
output application/json
---
payload]]></ee:set-payload>
            </ee:message>
        </ee:transform>
    </flow>
    <flow name="crm-retrieve-update-contacts" >
        <http:listener
            doc:name="Listener"
            config-ref="HTTP_Listener_config"
            path="/updated-contacts"/>
        <microsoft-dynamics-crm:retrieve-multiple-by-query
            doc:name="Retrieve multiple by query"
            config-ref="Microsoft_Dynamics_CRM_Dynamics_CRM">
            <microsoft-dynamics-crm:query ><![CDATA[dsql:SELECT contactid,description FROM contact WHERE address1_city = 'DemoCity']]></microsoft-dynamics-crm:query>
        </microsoft-dynamics-crm:retrieve-multiple-by-query>
        <ee:transform doc:name="Transform Message" >
            <ee:message >
                <ee:set-payload ><![CDATA[%dw 2.0
output application/json
---
payload]]></ee:set-payload>
            </ee:message>
        </ee:transform>
    </flow>
</mule>