Web Service

The entry point for a Process - you would build one endpoint per process. Once connected, messages are guided to the integration based on the unique combination of authentication user & endpoint.

Scripted REST Service

In native ServiceNow, navigate to System Web Services > Scripted Web Services > Scripted REST APIs. Click New.

The Scripted REST Service fields to be configured are as follows:

#

Field

Description

Value

1

Name

The name of the API. Appears in API documentation.

<Your Name>

2

API ID

The API identifier used to distinguish this API in URI paths. Must be unique within API namespace.

Automatically populated

*

API namespace

The namespace the API belongs to. The value depends on the current application scope.

Automatically populated

*

Base API path

The base API path (URI) to access this API.

Automatically populated (after 'Save')

The top section of your Scripted REST Service record should look like this:

3) Save the record.

Security Fields

Click on the 'Security' tab and configure the fields as follows:

#

Field

Description

Value

4

Default ACLs

The ACLs to enforce when accessing resources. Individual resources may override this value.

[Blank]

Your 'Security' tab should look like this:

Save the record.

Scripted REST Resource

Navigate to the Resources Related List. Click New.

The 'Scripted REST Resource' fields to be configured are as follows:

#

Field

Description

Value

5

Name

The name of this API resource. Appears in API documentation.

<Your Name>

6

HTTP method

The HTTP method that maps to this resource.

'POST'

*

Relative path

The path of this resource relative to the base API path. Can contain templatized path parameters such as /{id}.

'/' (Automatically populated)

7

Script

The script that implements the resource.

Replace the contents of the script field with your REST API code, substituting your Process API name (see below). E.g. var helper = new x_snd_eb.RestHelper('incident_guide');

*These fields are automatically populated.

The code in the Script field should look like this:

(function process(/*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {

    x_snd_eb.ws_console.execute('Request received', function() {
        var helper = new x_snd_eb.RestHelper('incident_guide'); // the API name of the Unifi Process
        processAttachment(helper.getRequest().getRecord());
        helper.processRequest(request, response, 'POST'); // the HTTP method of the resource
    });

    /**
     * This scripted REST API allows an attachment to be sent into Unifi in a
     * similar way to the OOB api/now/attachment REST API, but it processes it
     * in Unifi.
     *
     */
    function processAttachment(target_record) {
      var file_name = request.queryParams.file_name;
      var reference = request.queryParams.reference;
      var mime_type = request.getHeader('Content-Type');

      if (!file_name || !reference || !mime_type) return;

      var ga = new GlideSysAttachment();

      // save the body to an attachment on the request
      var attachment_id = ga.writeContentStream(target_record, file_name, mime_type, request.body.dataStream);

      // return custom payload for the body to process
      helper._getRequestBody = function _getRequestBody() {
        return '{\n' +
          '"message":    { "name": "AddAttachment" },\n' +
          '"reference": "' + reference + '",\n' +
          '"attachment": "<x-attachment-data sys_id=\"' + attachment_id + '\" />"\n' +
        '}';
      };
    }

})(request, response);

In the RestHelper function, change the value of the Process API name being called to match yours (e.g. 'incident_guide'). By wrapping the code in console, we give context to Activity Log and prevent multiple database updates.

The top section of your Scripted REST Resource should look like this:

Security Fields

Click on the 'Security' tab and configure the fields as follows:

#

Field

Description

Value

8

Requires ACL authorization

Enforce ACLs when this resource is accessed.

<false>

Your 'Security' tab should look like this:

Content Negotiation Fields

Click on the 'Content Negotiation' tab and configure the fields as follows:

#

Field

Description

Value

9

Override supported request formats

Check to customize the request media types supported by this resource.

<true>

10

Supported request formats

Comma-delimited list of media types this resource can consume.

*

Your 'Content Negotiation' tab should look like this:

11) Click Submit.

Update Process Record

With the introduction of the Packager feature, if you want the Web Service to be included in the packaged update set, you will need to update the value of the REST Service field on the Process record with the name of your Scripted REST Service. This will enable the Packager to pick it up.

Whilst still in native ServiceNow, navigate to [ws] Unifi > Configuration > Processes.

Click to open < Your Process >.

12) Update the value in the REST Service field with < Your Scripted REST Service > (as created above).

13) Click Update.

We will now move back to the Unifi Integration Designer window to configure the Integration.

Last updated