The CreatorCon Call for Content is officially open! Get started here.

Rogers Cadenhe1
Giga Guru

There's a long-unanswered question in the community about how to do an XML-RPC integration in ServiceNow.

An XML-RPC request is an HTTP POST request that can be implemented as an outbound REST message with a body containing the XML-RPC envelope.

Here's how to create an XML-RPC request that sends a ping to the XML-RPC API of Pingomatic, a service that receives messages whenever a blog has been updated with a new post.

In the filter navigator, choose System Web Services > Outbound > REST Message and then click New. The REST Message form opens.

Give it the Name Pingomatic XML-RPC Test and the Endpoint http://rpc.pingomatic.com.

Click Submit

Open the new REST message you just created.

In the HTTP Methods section, there should be one record for the endpoint. Open that record.

Change the Name to Default POST and the HTTP Method to Post.

Click the HTTP Request tab to bring it to the front.

In the Content field, enter this XML:

<?xml version="1.0"?>
<methodCall>
   <methodName>weblogUpdates.ping</methodName>
      <params>
         <param>
            <value><string>${blog_name}</string></value>
         </param>
         <param>
            <value><string>${blog_url}</string></value>
         </param>
      </params>
</methodCall>

This is a template for an XML-RPC request to Pingomatic. The parameters will be different in number and data type on other integrations.

In the request, the methodName element identifies the XML-RPC method. The two string elements will contain the parameters to the method. In this template, they are variables that will be replaced with real values in the actual request.

In the Related Links section of the form, click Auto-Generate Variables. Two records are created in the Variable Substitutions tab: one named blog_name and another named blog_url.

In the Test Value column, set the field for blog_name to Example Blog and the field for blog_url to http://www.example.com/.

In Related Links, click Test.

An XML-RPC request is made using the test values and a Test Run record is opened. Here's what the test looks like if the request connected successfully.

find_real_file.png

Here's some code that makes an XML-RPC request using this REST message and HTTP method:

// change scopeId to the scope your REST message was created in (or leave blank if global)
var scopeId = 'x_12345_needit.'; // make sure to include the period at the end
var sm = new sn_ws.RESTMessageV2(scopeId + 'Pingomatic XML-RPC Test', 'Default POST');
sm.setStringParameter('blog_name', 'Example 2');
sm.setStringParameter('blog_url', 'http://www.example.com/2');
var response = sm.execute();
gs.info(response.getBody());

This code doesn't do anything with the response except to display it in the logs. You could parse the XML and create or update records with the data, store data in an import set table that is the source of a table transform map, and process it in other ways.

The Response field of the test in the Test Runs tab of the HTTP Method form shows the XML structure of what is sent back as the XML-RPC response. Pingomatic sends this back upon a successful call:

<?xml version="1.0"?>
<methodResponse>
  <params>
    <param>
      <value>
        <struct>
          <member>
            <name>flerror</name>
            <value>
              <boolean>0</boolean>
            </value>
          </member>
          <member>
            <name>message</name>
            <value>
              <string>Pings being forwarded to 3 services!</string>
            </value>
          </member>
        </struct>
      </value>
    </param>
  </params>
</methodResponse>

You can generate more example code on the HTTP Method form by choosing Preview Script Usage in the Related Links section.

Note: I created this tutorial on an Orlando personal dev instance (PDI) but it should work on multiple versions going back to Kingston or London.

Version history
Last update:
‎03-18-2021 10:11 AM
Updated by: