Nav

Example: To Get a ServiceNow Incident Record

This example creates a Mule flow that retrieves a record based on an Incident number.

  1. Create a Mule application as a project.

  2. Add and configure an HTTP Listener as a trigger for your flow, and set a Path such as this one:

    /incident/get

    You can use the default configuration for the Listener connection.

  3. After the HTTP Listener, add the Invoke operation from the ServiceNow connector to your flow.

  4. Set up and test a ServiceNow configuration for the connection to the ServiceNow server, for example:

    • Configuration Name: My ServiceNow Config

    • Username: my_user_name

    • Password: my_password

    • Service Address: https://my_account.service-now.com

    • Service Now Version: Istanbul

      If the connection test is unsuccessful, you should correct any invalid connection parameters and then retest the connection.

  5. In the Transport tab for the ServiceNow configuration, set up, test, and save a Basic Auth HTTP Message Dispatcher Provider with the same Username and Password that you provided within the General tab, for example:

    • Username: my_user_name

    • Password: my_password

      If the connection test is unsuccessful, you should correct any invalid connection parameters and then retest the connection.

  6. Select the Web Service Configuration values for the ServiceNow connector, for example:

    • Service: incident

    • Operation: getRecords

      You need to make sure that the values are available as menu items in the Service and Operation fields. The names become available once the connector loads the metadata for them. Do not type the names manually.

  7. Provide a transformation script for the connector.

    In your Invoke operation in Design Center, you click the Map button for the Body, then click the Script tab at the bottom of the Body window, and paste a Transformation script like this one:

    %dw 2.0
    output application/xml
    ns inc http://www.service-now.com/incident
    ---
    {
        inc#getRecords: {
            inc#number: "INC0012345"
        }
    }

    Note that this example changes the output data type to application/xml.

  8. Add a Logger to the end of your flow that takes payload as the message.

  9. Deploy, Sync, or Run the app.

  10. To test the app, open http://url.for.your.app:8081/incident/get from a browser or from an app such as Postman.

    The response should look something like this (many fields omitted for brevity):

    <getRecordsResponse xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      <getRecordsResult>
        <active>1</active>
        <additional_assignee_list/>
        <approval>not requested</approval>
        <business_stc>0</business_stc>
        <calendar_duration/>
        <calendar_stc>0</calendar_stc>
        <caller_id>6816f79cc0a8016401c5a33be04be441</caller_id>
        <category>inquiry</category>
        <escalation>0</escalation>
        <knowledge>0</knowledge>
        <made_sla>1</made_sla>
        <notify>1</notify>
        <number>INC0021195</number>
        <opened_at>2017-07-27 03:13:54</opened_at>
        <opened_by>6816f79cc0a8016401c5a33be04be441</opened_by>
        <order>0</order>
        <priority>5</priority>
        <short_description>Server outage</short_description>
        <state>1</state>
        <sys_class_name>incident</sys_class_name>
        <sys_created_by>admin</sys_created_by>
        <sys_created_on>2017-07-27 03:14:52</sys_created_on>
        <sys_domain>global</sys_domain>
      </getRecordsResult>
    </getRecordsResponse>

In this topic: