Contact Us 1-800-596-4880

Extract Payload Information to Variables

logo cloud IDE Cloud IDE

logo desktop IDE Desktop IDE

Open Beta Release: The cloud IDE and AsyncAPI implementation support are in open beta. Any use of Anypoint Code Builder in its beta state is subject to the applicable beta services terms and conditions, available from the IDE.

This section of the tutorial teaches you how to extract information from the payload into different variables to refer to those values later in the flow.

Before You Begin

Extract Values From the Payload

  1. In Anypoint Code Builder, open your new-case-salesforce.xml file.

  2. Click the (Add component) icon after the On New Case Salesforce component:

    add transform from canvas slack
  3. Type Transform and select Transform.

  4. Configure the Transform Message component to extract data from the payload to variables:

    <ee:transform doc:name="Extract Values from Case" >
        <ee:variables>
          <ee:set-variable variableName="casestatus"> (1)
              <![CDATA[%dw 2.0 output application/java --- payload.Status]]>
          </ee:set-variable>
          <ee:set-variable variableName="casenumber"> (2)
              <![CDATA[%dw 2.0 output application/java --- payload.CaseNumber]]>
          </ee:set-variable>
    <ee:set-variable variableName="slackchannel"> (3)
              <![CDATA["this-is-a-test"]]>
          </ee:set-variable>
        </ee:variables>
      </ee:transform>
    1 casestatus retrieves the Salesforce case status: New, Working, or Escalated.
    2 casenumber retrieves the case number created by Salesforce.
    3 Set the slackchannel to the channel name that you set earlier in the tutorial.

Concatenate Your Values in The Payload

Add a Set Payload component to concatenate the value of your variables in the resulting payload of your application:

  1. Click the (Add component) icon after the Transform Message component:

    add set payload slack case canvas
  2. Type set and select Set Payload.

  3. Configure the Set Payload component with the following code:

    <set-payload doc:name="Set Case Info" value='#["Case Number: " ++ (payload.CaseNumber default "") ++  ", Origin: " ++ (payload.Origin default "") ++ ", Case Type: " ++ (payload.Type default "") ++ ", Priority: " ++ (payload.Priority default "") ++ ", Status: " ++ (payload.Status default "")]'/>
  4. Proceed to Add a Condition to Your Flow Logic to create a condition to send an email if the case is escalated or otherwise inform about the case in a Slack channel.