2 Replies Latest reply on Feb 20, 2018 1:13 PM by Christopher.Bakken

    XSLT Help - Email Listener

    DO-ISM Rookie

      Hello All,

       

      I am in need of assistance with building an xsl file for an email listener I am configuring. I am very close (with help from a template) but stumped on one section. I am needing the listener to create the service request based on the name of a person from which the email defines by "Custid="user_name". Currently the xsl file I am working with creates the service request from who the email is sent.

       

      An example of what the file is current doing would be: I send an email from the account [email protected]. The ticket will be created under the name John Doe because John Doe has a user account in our system.

       

      If I was to send an email from [email protected], no tickets is created because there is no associated account for SharePoint in our system. The email that the requests will be coming from will be like this example though, so the ticket needs to be created based on a parameter in the email. An example of the incoming email for reference would be:

       

      Subject: SharePoint ADM Request

       

       

      Body:
      ADM Request details:

      Request ID:310

      Applicant: Doe, John

      Manager: Doe, Jane

      Reason For Requesting: Maintenance, software installation, and group support for shared linux machines used to run models and store data.

      Type Of System: Server

      Name Of System:

      User Account: adm-jdoe

      Expiration Date: 1/2/2019 12:00:00 AM

       

      Custid=jdoe

      Category=Service Request

      Service_Area=Account, Identity, and Access Management

      CallType=Account Setup

      AsgnGrp=Tier 1

      SubGroup=Example

       

      From this email, I need the xsl file to pick out Custid=jdoe, parse that information, and then create the service request in the name of John Doe. "jdoe" is John Doe's user name in our system for clarification.

       

      I have attached the Main xslt file (main_xslt.txt) and the Service Request xsl file (SR_import.xsl) I am working with to try and accomplish this. Everything else in these files is working to my expectation, we are just focusing on the ticket creation based on "Custid" for this post.

       

      My best guess is modifications to the section below from the SR_import.xsl file will need to be made, but I am not sure:

       

      <!-- find the profile link recid of the email sender, they will be the service requestor/customer-->

      <xsl:variable name="ProfileRecId">

      <xsl:for-each select="BusinessObjectList/BusinessObject/RelatedBusinessObjectList/RelatedBusinessObject/BusinessObject">

      <xsl:choose>

      <xsl:when test="@Name = 'Employee'">

      <xsl:for-each select="./FieldList/Field">

      <xsl:choose>

      <xsl:when test="@Name = 'RecId'">

      <xsl:value-of select="."/>

      </xsl:when>

      </xsl:choose>

      </xsl:for-each>

      </xsl:when>

      </xsl:choose>

      </xsl:for-each>

      </xsl:variable>

       

      Please let me know if any of this needs any further explanation.

       

      Thank you very much to anyone assisting!

        • 1. Re: XSLT Help - Email Listener
          Christopher.Bakken SupportEmployee

          The help file has some good XSLT examples.

           

          https://help.ivanti.com/ht/help/en_US/ISM/2017/Index.html#Configure/Email/Export Email Examples.htm

           

          XSLT Introduction

           

          XSLT is a bit of a beast. There are a few tools you can use to apply the XSLT transformation to the payload outside of the application. This should allow you for faster development as you aren't having to send in a new email each time you want to test your edits. NP++ has a plugin called XMLTools that can apply the xslt transformation. There are some online converters as well.

           

          You can pull the raw email payload from the 'Message Queue Journal' workspace. If you are compressing your messages, you will have to run the decompress quick action to view the payload in plain text. You can then copy the entire XML chunk out to test outside of the application.

           

           

           

          This is one example you can work off of. The example script provided first runs a condition on the subject, it if matches, it then searched the body for each variable, you would alter it to look for the variables you want with different delimiters.

           

          You pull the variable by using a select statement against the $Body variable, which is the entire <body></body> XML block.

           

          xsl:choose is really just a CASE/SELECT statement.

           

          Subject:

          Request - Domain Password Reset

           

          Body:

           

          Department$IT

          Requester$Alan Taylor

          [email protected]

           

          <xsl:choose>

          <!-- There will be a separate when section for each type of service request supported -->

          <xsl:when test="contains($Subject,'Domain Password Reset')">

          <!-- Now let's parse the body for the fields we want for a domain password reset -->

          <!-- Department: -->

          <xsl:variable name="dept" select="substring-after($Body,'Department$')"/>

          <!-- Stop at the newline character -->

          <!-- Requester: -->

          <xsl:variable name="requestor" select="substring-after($Body,'Requester$')"/>

          <!-- Email: -->

          <xsl:variable name="email" select="substring-after($Body,'Email$')"/>

           

           

           

          <!-- Fill in the necessary fields and related business objects for a domain password reset -->

          <FieldList>

          <Field Name="SvcReqTmplLink" Type="System.String">Domain Password Reset</Field>

          <!-- Replace this subscription RecID with the valid one for your system: -->

          <Field Name="SvcReqSubscLink_RecID"Type="System.String">BDF2D75B420C438E9468BC613E6AB369</Field>

          <Field Name="Price">150.00</Field>

          <Field Name="ProfileLink_RecID" Type="System.String">

          <xsl:value-of select="$ProfileRecId"/>

          </Field>

          </FieldList>

          <RelatedBusinessObjectList>

          <RelatedBusinessObject Relationship="ServiceReqContainsServiceReqParam">

          <BusinessObject Name="ServiceReqParam">

          <Transaction>Insert</Transaction>

          <LinkTransaction>Link</LinkTransaction>

          <UniqueKeyList>

          <UniqueKey>

          <Field Name="RecId"/>

          </UniqueKey>

          </UniqueKeyList>

          <FieldList>

          <Field Name="ParameterName"Type="System.String">RequesterDepartment</Field>

          <Field Name="ParameterValue" Type="System.String">

          <xsl:choose>

          <xsl:when test="contains($dept, ' ')">

          <xsl:value-of select="substring-before($dept,' ')"/>

          </xsl:when>

          <xsl:otherwise>

          <xsl:value-of select="$dept"/>

          </xsl:otherwise>

          </xsl:choose>

          </Field>

          <Field Name="DisplayType" Type="System.String">text</Field>

          </FieldList>

          </BusinessObject>

          </RelatedBusinessObject>

          <RelatedBusinessObject Relationship="ServiceReqContainsServiceReqParam">

          <BusinessObject Name="ServiceReqParam">

          <Transaction>Insert</Transaction>

          <LinkTransaction>Link</LinkTransaction>

          <UniqueKeyList>

          <UniqueKey>

          <Field Name="RecId"/>

          </UniqueKey>

          </UniqueKeyList>

          <FieldList>

          <Field Name="ParameterName" Type="System.String">Requester</Field>

          <Field Name="ParameterValue" Type="System.String">

          <xsl:choose>

          <xsl:when test="contains($requestor, ' ')">

          <xsl:value-of select="substring-before($requestor,' ')"/>

          </xsl:when>

          <xsl:otherwise>

          <xsl:value-of select="$requestor"/>

          </xsl:otherwise>

          </xsl:choose>

          </Field>

          <Field Name="DisplayType" Type="System.String">text</Field>

          </FieldList>

          </BusinessObject>

          </RelatedBusinessObject>

          <RelatedBusinessObject Relationship="ServiceReqContainsServiceReqParam">

          <BusinessObject Name="ServiceReqParam">

          <Transaction>Insert</Transaction>

          <LinkTransaction>Link</LinkTransaction>

          <UniqueKeyList>

          <UniqueKey>

          <Field Name="RecId"/>

          </UniqueKey>

          </UniqueKeyList>

          <FieldList>

          <Field Name="ParameterName" Type="System.String">Email</Field>

          <Field Name="ParameterValue" Type="System.String">

          <xsl:choose>

          <xsl:when test="contains($email, ' ')">

          <xsl:value-of select="substring-before($email,' ')"/>

          </xsl:when>

          <xsl:otherwise>

          <xsl:value-of select="$email"/>

          </xsl:otherwise>

          </xsl:choose>

          </Field>

          <Field Name="DisplayType" Type="System.String">text</Field>

          </FieldList>

          </BusinessObject>

          </RelatedBusinessObject>

          </RelatedBusinessObjectList>

          </xsl:when>

          <!-- Next service request type would placed here in its own xsl:when block -->

          <xsl:otherwise>

          <other/>

          </xsl:otherwise>

          </xsl:choose>

           

           

          Working in Notepad++

          1. Save the XSLT file you are using in the import as a separate XSL file. (.XSL)

           

          2. Copy the entire payload from Message Queue Journal to a new file

           

          3. With the file open, go to Plugins > XML Tools > XSL Transformation

          4. Select the XSLT file you saved earlier and click on “Transform” (This fails against XML files, just rename it to XSL if you didn’t do that earlier.)

           

          5. A new file will be opened with the transformation.

          7. The file should now be in the correct format to import based on the hierarchical xml example, if not, adjust your XSLT file and try again until it is in the correct format.

          • 2. Re: XSLT Help - Email Listener
            Christopher.Bakken SupportEmployee

            The code you identified is working off of the payload data. The payload is holding the RecID of the sender, which is being generated and inserted by the system as a part of the payload creation process. Since you don't have a RecID for the value you are working with, you will have to explore other routes to get the data in the desired area.

             

            One such route would be to establish a 'Search and Link' action that runs after insert that searches the value and links the match. So you should be able to parse and save that custid value into a custom field, then the action can be applied against that value to link it to the desired account after creation.

             

             

             

             

             

             

            <xsl:for-each select="./ FieldList / Field">

             

            <Body>Department$IT Requester$Alan Taylor [email protected] </Body>

            </EmailMessage>

            <RelatedBusinessObjectList>

            <RelatedBusinessObject Relationship="">

            <BusinessObject Name="Employee">

            <Transaction>None</Transaction>

            <LinkTransaction>None</LinkTransaction>

            <UniqueKeyList>

            <UniqueKey>

            <Field Name="PrimaryEmail"/>

            </UniqueKey>

            </UniqueKeyList>

             

            <FieldList>

            <Field Name="RecId">3734B48625D043B0939456EBF5B07F43</Field>

            <Field Name="PrimaryEmail">[email protected]</Field>

            </FieldList>