Share via


Creating XSLT for the Update operation

To modify an existing document, use XSLT to transform the document into an eConnect XML input document. Typically, the update operation uses the same eConnect XML document and business object as the create operation. This allows you to re-use the XSLT in your create file. To create the XSLT for an Update operation, complete the following steps:

  1. Create an XSLT file.

    Start Visual Studio. In the File menu, point to New, and then click File. In the New File window, select XSLT File and click Open. Visual Studio creates a file.

    Remove the existing xsl:template node.

  2. Add required namespaces.

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

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

    • xmlns:xsd="http://www.w3.org/2001/XMLSchema"

    • 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 LeadUpdate.xslt file.

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

version="1.0">

  1. Import required libraries.

    Add xsl:import nodes that specify files that contain additional templates. The files are in the service "XSLT" folder, typically found in the following location:

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

    Notice how the following XSLT sample requires you to import two XSLT files.

    • The Microsoft.Dynamics.GP.Samples.Leads.LeadCreae.xslt file contains the template you created for the Create operation of the Lead Service. This allows you to use the same eConnect XML document and business object for the update operation.

    • The Microsoft.Dynamics.GP.StandardLibrary.xslt file contains supporting templates and definitions used across all Dynamics GP Service operations.

    Also notice that the import does not include the file path for the .xslt files. The XSLT file being created must be located in the same folder as the LeadCreate.xslt and StandardLibrary.xslt files.

    <xsl:import href="Microsoft.Dynamics.GP.Samples.Leads.LeadCreate.xslt"/>
    

<xsl:import href="Microsoft.Dynamics.GP.StandardLibrary.xslt"/>

  1. Specify the templates.

    Add an xsl:template node to the stylesheet. Use the match attribute of the template node to specify the nodes in the document to transform. Also, specify the template to use to transform the document type.

    The following code sample shows the templates used to update a lead. Notice how the xsl:call-template specifies the Lead template. The Lead template is in the Microsoft.Dynamics.GP.Samples.Leads.LeadCreae.xslt file that was imported in the previous step.

    <xsl:template match = "/">
    <xsl:call-template name="Lead">
    </xsl:call-template>
    

</xsl:template>

  1. Implement policy for specified nodes.

    Use the policy information that the framework adds to the document to identify behaviors that apply to a node or set of nodes. Add XSLT that implements each behavior option for each behavior.

    The following example adds the Lead Update Policy to the LeadCreate.xslt file. The Lead Update Policy does not have any behaviors. Note the use of XSLT in the following areas:

    • The use of xsl:if to identify the policy. The value of Policy/Key/Id node is compared to the GUID of the Lead Update Policy. If they match, an update operation is being performed.

    • When an update operation is performed, the template uses values from the lead document to populate the QualifiedLead, LeadSource, and QualificationDate properties.

    <xsl:if test="Lead/Policy/Key/Id =
    '443e9afd-50e0-44e2-a2f1-8fffc2dce596'">
    <QualifiedLead>
        <xsl:if test="Lead/QualifiedLead != ''">
            <xsl:choose>
                <xsl:when test="Lead/QualifiedLead='true'">2</xsl:when>
                <xsl:otherwise>1</xsl:otherwise>
            </xsl:choose>
        </xsl:if>
    </QualifiedLead>
    <LeadSource>
        <xsl:value-of select="Lead/LeadSource"/>
    </LeadSource>
    <QualificationDate>
        <xsl:choose>
            <xsl:when test="Lead/QualificationDate=
                '0001-01-01T00:00:00'">1/1/1900</xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="gputil:GetDate(
                    Lead/QualificationDate)"/>
            </xsl:otherwise>
        </xsl:choose>
    </QualificationDate>
    

</xsl:if>

  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.