Phidiax Tech Blog

Adventures in custom software and technology implementation.

BizTalk Integration with Dynamic CRM - Deactivating Record(s)

A while back, we created a new BizTalk application to integrate contact data with Dynamics CRM. One of the steps was to deactivate a contact in the Contact entity without deleting the record.

We learned that we needed to update both the “State” and “Status” fields with the appropriate value. Since the BizTalk application is going to receive one or more contactID, we decided to use the “Execute” method of iOrganizationService to send the data to CRM in one single transaction.  

In the below xslt mapping sample, you can see that we've mapped the ContactID, ContactStatus, and ContactState fields.

 

<?xml version="1.0" encoding="UTF-16"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt"
                xmlns:var="http://schemas.microsoft.com/BizTalk/2003/var"
                exclude-result-prefixes="msxsl var s0 s1 s2 s8 s3 s4 s5 s6 s7 s9 userCSharp" version="1.0"
                xmlns:ns3="http://schemas.microsoft.com/xrm/2011/Metadata"
                xmlns:ns4="http://schemas.microsoft.com/xrm/2011/Contracts"
                xmlns:ns2="http://schemas.microsoft.com/2003/10/Serialization/Arrays"
                xmlns:ns1="http://schemas.datacontract.org/2004/07/System.Collections.Generic"
                xmlns:ns5="http://schemas.microsoft.com/2003/10/Serialization/"
                xmlns:ns0="http://schemas.microsoft.com/xrm/2011/Contracts/Services"
                xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

  <xsl:output omit-xml-declaration="yes" method="xml" version="1.0" />

  <xsl:template match="/">
    <xsl:apply-templates select="/s1:ContactCanonical" />
  </xsl:template>

  <xsl:template match="/s1:ContactCanonical">
    <ns0:Execute>
      <ns0:request>
        <ns4:Parameters>
          <!-- Setting -->
          <ns4:KeyValuePairOfstringanyType>
            <ns1:key>Settings</ns1:key>
            <ns1:value xsi:type="ns6:ExecuteMultipleSettings" xmlns:ns6="http://schemas.microsoft.com/xrm/2012/Contracts" >
              <ns4:ContinueOnError>true</ns4:ContinueOnError>
              <ns4:ReturnResponses>true</ns4:ReturnResponses>
            </ns1:value>
          </ns4:KeyValuePairOfstringanyType>

          <!--Root request-->
          <ns4:KeyValuePairOfstringanyType>
            <ns1:key>Requests</ns1:key>
            <ns1:value xsi:type="ns6:OrganizationRequestCollection" xmlns:ns6="http://schemas.microsoft.com/xrm/2012/Contracts">
              <!--Begin Looping-->
              <xsl:for-each select="s0:Contact">
                  <xsl:if test="string(ContactStatus/text())">
                      <ns6:OrganizationRequest >
                        <ns4:Parameters>

                          <xsl:if test="string(ContactState/text())">
                            <ns4:KeyValuePairOfstringanyType>
                              <ns1:key>State</ns1:key>
                              <xsl:call-template name="SetOptionSetValue">
                                <xsl:with-param name="param1" select="string(ContactState/text())" />
                              </xsl:call-template>
                            </ns4:KeyValuePairOfstringanyType>
                          </xsl:if>

                          <xsl:if test="string(ContactStatus/text())">
                            <ns4:KeyValuePairOfstringanyType>
                              <ns1:key>Status</ns1:key>
                              <xsl:call-template name="SetOptionSetValue">
                                <xsl:with-param name="param1" select="string(ContactStatus/text())" />
                              </xsl:call-template>
                            </ns4:KeyValuePairOfstringanyType>
                          </xsl:if>

                          <ns4:KeyValuePairOfstringanyType>
                            <ns1:key>EntityMoniker</ns1:key>
                            <ns1:value xsi:type="ns4:EntityReference">
                              <ns4:Id>
                                  <xsl:value-of select="string(ContactID/text())" />
                              </ns4:Id>
                              <ns4:LogicalName>
                                <xsl:value-of select="'Contact'" />
                              </ns4:LogicalName>
                              <ns4:RelatedEntities xsi:nil="true" />
                            </ns1:value>
                          </ns4:KeyValuePairOfstringanyType>

                        </ns4:Parameters>
                        <ns4:RequestName>SetState</ns4:RequestName>
                        <ns4:RequestId>
                          <xsl:attribute name="xsi:nil">
                            <xsl:value-of select="'true'" />
                          </xsl:attribute>
                        </ns4:RequestId>
                      </ns6:OrganizationRequest>
                    </xsl:if>
              </xsl:for-each>
              <!--End Loop-->
            </ns1:value>
          </ns4:KeyValuePairOfstringanyType>
        </ns4:Parameters>
        <ns4:RequestName>
          <xsl:value-of select="'ExecuteMultiple'" />
        </ns4:RequestName>
        <ns4:RequestId>
          <xsl:attribute name="xsi:nil">
            <xsl:value-of select="'true'" />
          </xsl:attribute>
        </ns4:RequestId>
      </ns0:request>
    </ns0:Execute>
  </xsl:template>


Here is a sample request message. 



Loading

Privacy Policy  |  Contact  |  Careers

2009-2017 Phidiax, LLC - All Rights Reserved