Share via


Creating XSLT for the GetByKey operation

To retrieve a specified document, create XSLT that transforms the eConnect Transaction Requester document into the business document that the service framework uses. To create the XSLT for the GetByKey operation, complete the following steps:

  1. Create the XSLT file.

    Start Visual Studio. In the File menu, point to New, and then click File. In the New File window, select General from the list of Categories. Select XSLT File from the Templates, and then click Open. Visual Studio creates an XSLT file.

    If the file contains an <xsl:template /> example node, delete that node from the file. Your XSLT should be similar to the the following example.

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

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

</xsl:stylesheet>

  1. Add required namespaces.

    Add the following namespaces as attributes to the xsl:stylesheet node:

    • xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

    • xmlns:ms ="urn:schemas-microsoft-com:xslt"

    • xmlns:gpxslt="uri://GreatPlainsTransformLibrary"

    • xmlns:gputil="urn:Microsoft.Dynamics.GP.TransformUtilities"

    • xmlns:mbs="https://schemas.microsoft.com/dynamics/2006/01"

    The following code sample shows the xsl:stylesheet node from the LeadGetByKey.xslt file.

    <xsl:stylesheet
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:ms ="urn:schemas-microsoft-com:xslt"
    xmlns:gpxslt="uri://GreatPlainsTransformLibrary"
    xmlns:gputil="urn:Microsoft.Dynamics.GP.TransformUtilities"
    xmlns:mbs="https://schemas.microsoft.com/dynamics/2006/01"
    

version="1.0">

  1. Import required libraries.

    Add an xsl:import node for the Microsoft.Dynamics.GP.StandardLibrary. The file is in the service "XSLT" folder, typically found in the following location:

    C:\Program Files\Microsoft Dynamics\GPWebServices\XSLT

    Notice how the following XSLT sample uses an xsl:import node to add the library. Also notice that the import does not include the file path for the .xslt file. The XSLT file being created must be located in the same folder as the StandardLibrary.xslt file.

    <xsl:import href="Microsoft.Dynamics.GP.StandardLibrary.xslt"/>
    
  1. Specify the templates.

    Add xsl:template nodes to the stylesheet. The first node identifies XML documents produced by the eConnect Transaction Requester. The xsl:apply-templates node applies the remaining templates to the nodes in the XML document.

    <xsl:template match = "root/eConnect">
    <xsl:apply-templates />
    

</xsl:template>

Next, add an xsl:templates node that specifies the name of the document type.

The following sample adds a template for a Lead. Notice how the XSLT template name of "Lead" matches the value that was placed in the ALIAS field of the eConnect\_Out\_Setup table.

<pre class="checklistscript" IsFakePre="true" xmlns="http://www.w3.org/1999/xhtml">&lt;xsl:template match ="Lead"&gt;

</xsl:template>

  1. Define variables.

    Add variables that can be used to supply default values for nodes in your document.

    The following sample shows how to create variables named "isocode" and "decimaldigits". The value of each variable is retrieved from the StandardLibrary.

    <xsl:variable name="isocode">
    <xsl:value-of select="gputil:LocalCurrency(
        /root/mbs:Context/mbs:OrganizationKey/mbs:Id)"/>
    

</xsl:variable> <xsl:variable name="decimaldigits" select="gputil:CurrencyDecimalDigits($isocode)" />

  1. Add the document nodes.

    Add XML to the template that reflects the nodes of the business document that is returned from the service.

    The following example shows the XML nodes for a lead document. Notice how the XML specifies individual property names for objects like Key, Phone1, Phone2, Fax, and PotentialRevenue.

    <Lead>
    <Key>
        <Id>
        </Id>
    </Key>
    <Name>
    </Name>
    <SalespersonID>
    </SalespersonID>
    <City>
    </City>
    <State>
    </State>
    <Zip>
    </Zip>
    <Address1>
    </Address1>
    <Address2>
    </Address2>
    <Phone1>
        <Value>
        </Value>
    </Phone1>
    <Phone2>
        <Value>
        </Value>
    </Phone2>
    <Fax>
        <Value>
        </Value>
    </Fax>
    <LeadBusinessCategory>
    </LeadBusinessCategory>
    <Country>
    </Country>
    <Contact>
    </Contact>
    <PotentialRevenue>
        <Currency>
        </Currency>
        <Value>
        </Value>
        <DecimalDigits>
        </DecimalDigits>
    </PotentialRevenue>
    <QualifiedLead>
    </QualifiedLead>
    <LeadSource>
    </LeadSource>
    <QualificationDate>
    </QualificationDate>
    <WorflowApprovalStatus>
    </WorflowApprovalStatus>
    <WorkflowPriority>
    </WorkflowPriority>
    <ApprovedSalespersonID>
    </ApprovedSalespersonID>
    <ModifiedDate>
    </ModifiedDate>
    

</Lead>

  1. Add values to the document nodes.

    To complete the XSLT transform, populate each node with a value from the eConnect Transaction Requester XML document.

    When the eConnect Transaction Requester retrieves a document, it creates an XML document with nodes that contain values from the Dynamics GP source table. The Transaction Requester uses the column name from the table as the name of the node. Your XSLT needs to copy values from the eConnect nodes into your business document nodes.

    The following example shows XSLT to retrieve a single lead document. Notice the use of the following XSLT nodes:

    • The <xsl:value-of /> node to get the value for the node. The select= attribute specifies the name from the Transaction Requester XML document that maps to current property.

    • The <xsl:variable /> nodes. These nodes add the "isocode" and "decimaldigits" variables from the StandardLibrary. These variables supply values for the PotentialRevenue properties. PotentialRevenue is a MoneyAmount that requires you to supply Currency and DecimalDigits values.

    • The LeadBusinessCategory node uses <xsl:choose \> to convert the enumeration integer value found in the database to the corresponding LeadBusinessCategory enumeration string value.

    • The QualifiedLead property maps the integer value retrieved from the database to the corresponding boolean value.

    • The <xsl:if /> that ensures the ModifiedDate is a valid date for Dynamics GP.

    <Lead>
    <Key>
        <Id>
            <xsl:value-of select="LeadID"/>
        </Id>
    </Key>
    <Name>
        <xsl:value-of select="LeadName"/>
    </Name>
    <SalespersonID>
        <xsl:value-of select="SLPRSNID"/>
    </SalespersonID>
    <City>
        <xsl:value-of select="CITY"/>
    </City>
    <State>
        <xsl:value-of select="STATE"/>
    </State>
    <Zip>
        <xsl:value-of select="ZIP"/>
    </Zip>
    <Address1>
        <xsl:value-of select="ADDRESS1"/>
    </Address1>
    <Address2>
        <xsl:value-of select="ADDRESS2"/>
    </Address2>
    <Phone1>
        <Value>
            <xsl:value-of select="PHONE1"/>
        </Value>
    </Phone1>
    <Phone2>
        <Value>
            <xsl:value-of select="PHONE2"/>
        </Value>
    </Phone2>
    <Fax>
        <Value>
            <xsl:value-of select="FAX"/>
        </Value>
    </Fax>
    <LeadBusinessCategory>
        <xsl:choose>
            <xsl:when test="LeadBusinessCategory=1">RealEstate</xsl:when>
            <xsl:when test="LeadBusinessCategory=2">Wholesale</xsl:when>
            <xsl:when test="LeadBusinessCategory=3">Retail</xsl:when>
            <xsl:when test="LeadBusinessCategory=4">Contractor</xsl:when>
            <xsl:when test="LeadBusinessCategory=5">Educational</xsl:when>
            <xsl:when test="LeadBusinessCategory=6">Media</xsl:when>
            <xsl:when test="LeadBusinessCategory=7">Software</xsl:when>
            <xsl:when test="LeadBusinessCategory=8">Restaurant</xsl:when>
        </xsl:choose>
    </LeadBusinessCategory>
    <Country>
        <xsl:value-of select="COUNTRY"/>
    </Country>
    <Contact>
        <xsl:value-of select="CONTACT"/>
    </Contact>
    <PotentialRevenue>
        <Currency>
            <xsl:value-of select="$isocode"/>
        </Currency>
        <Value>
            <xsl:value-of select="PotentialRevenue"/>
        </Value>
        <DecimalDigits>
            <xsl:value-of select="$decimaldigits"/>
        </DecimalDigits>
    </PotentialRevenue>
    <QualifiedLead>
        <xsl:choose>
            <xsl:when test="QualifiedLead=1">0</xsl:when>
            <xsl:when test="QualifiedLead=2">1</xsl:when>
        </xsl:choose>
    </QualifiedLead>
    <LeadSource>
        <xsl:value-of select="LeadSource"/>
    </LeadSource>
    <QualificationDate>
        <xsl:value-of select="QualificationDate"/>
    </QualificationDate>
    <WorflowApprovalStatus>
        <xsl:value-of select="Workflow_Approval_Status"/>
    </WorflowApprovalStatus>
    <WorkflowPriority>
        <xsl:value-of select="Workflow_Priority"/>
    </WorkflowPriority>
    <ApprovedSalespersonID>
        <xsl:value-of select="Approved_Salesperson_ID"/>
    </ApprovedSalespersonID>
    <xsl:if test="gputil:IsNotGreatPlainsDefaultDate(DEX_ROW_TS)">
        <ModifiedDate>
            <xsl:value-of select="DEX_ROW_TS"/>
        </ModifiedDate>
    </xsl:if>
    

</Lead>

  1. Save the file.

    In the File menu, choose Save As. In the Save File As window enter a filename that complies with Dynamics GP Service XSLT naming requirements. Review the Save in folder, and then click Save.