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:

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:

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:

*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:

Your 'Security' tab should look like this:

Content Negotiation Fields

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

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