LogoLogo
AboutSupport
2.2
2.2
  • Unifi Documentation
  • Release
    • Release Notes
      • 2.1 Release Notes
      • 2.0 Release Notes
    • Hotfixes
    • Setup
  • Overview
    • Quick Tour
    • Supported Features
    • Application Module Overview
  • Integration Guides
    • Outbound Incident Guide
      • Getting Started
      • Process
      • Integration
      • Connection
      • Trigger
      • Create Scenario
        • CreateIncidentResponse Message
        • CreateIncidentResponse Fields
        • CreateIncident Message
        • CreateIncident Fields
        • Test CreateIncident
      • Update Scenario
        • Response Message
        • UpdateIncident Message
        • UpdateIncident Fields
        • Test UpdateIncident
      • Resolve Scenario
        • ResolveIncident Message
        • ResolveIncident Fields
        • Test ResolveIncident
      • Build - Integration Level
      • Conclusion
    • Bidirectional Asynchronous Incident Guide
      • Getting Started
      • Process
      • Web Service
      • Integration
      • Connection
      • Trigger
      • Create Scenario
        • Response Message
        • CreateIncidentReceipt Message
        • CreateIncidentReceipt Fields
        • CreateIncident Message
        • CreateIncident Fields
        • Test CreateIncident
      • Update Scenario
        • Receipt Message
        • UpdateIncident Message
        • UpdateIncident Fields
        • Test UpdateIncident
      • Resolve Scenario
        • ResolveIncident Message
        • ResolveIncident Fields
        • Test ResolveIncident
      • Build - Integration Level
      • Build the Other Half
        • Move the Integration
        • Reconfigure the Connections
      • Conclusion
    • Incident Update Poller Guide
      • Polling
        • Poll Processor
        • Poller
      • Inbound Message
        • UpdateIncidentInbound Message
        • UpdateIncidentInbound Fields
      • Message Identification
      • Bond Identification
        • Edit Incident Form
        • Edit CreateIncident Message
      • Test Update Poll
      • Conclusion
    • Incident Multiple Message Poller Guide
      • Polling
        • Poll Processor
        • Poller
      • Inbound Messages
        • ResolveIncidentInbound Message
        • ResolveIncidentInbound Fields
      • Testing
        • Test UpdateIncidentInbound
        • Test ResolveIncidentInbound
      • Conclusion
    • Incident Create Poller Guide
      • Polling
        • Connection Variables
        • Poll Processor
        • Poller
      • Messages
        • CreateIncidentInboundReceipt Message
        • CreateIncidentInboundReceipt Fields
        • CreateIncidentInbound Message
        • CreateIncidentInbound Fields
      • Build - Integration Level
      • Test Create Poll
      • Conclusion
    • Incident Parent and Child Poller Guide
      • Polling
        • Connection Variables
        • Child Poll Processor
        • Child Poller
        • Parent Poll Processor
        • Parent Poller
      • Inbound Messages
      • Testing
        • Test UpdateIncidentInbound
        • Test ResolveIncidentInbound
      • Conclusion
    • Incident Attachment Poller Guide
      • Polling
        • Connection Variables
        • Edit Endpoint URLs
        • Get Attachment Poll Processor
        • Get Attachment Poller
        • Select Attachments Poll Processor
        • Select Attachments Poller
        • Edit Child Poll Processor
        • Edit Child Update Poller
      • Messages
        • AddAttachmentInbound Message
      • Testing
        • Test Outbound Scenarios
        • Test CreateIncidentInbound
        • Test UpdateIncidentInbound
        • Test ResolveIncidentInbound
        • Test AddAttachmentInbound
      • Conclusion
  • Feature Guides
    • Packager Feature Guide
      • Instructions
    • Error Handling Tools Feature Guide
      • Retry
      • Replay
      • Ignore
      • Repair
      • Pause and Resume
  • Bonding
    • Bonds
    • Bonded Attachments
  • Transport
    • Transport Data Flow
    • Transactions
    • Stages
    • HTTP Requests
    • Response Actions
  • Configuration
    • Processes
    • Integrations
    • Connections
    • Messages
    • Message Scripts
    • Fields
    • Field Maps
    • Event Actions
  • Polling
    • Pollers
    • Poll Processors
    • Poll Requests
    • Large Response Payloads
  • Administration
    • Activity Logs
    • Data Stores
    • Properties
    • Scheduled Scripts
    • System Logs
    • Self-test
  • Scripting
    • Variables
    • Snippets
  • Attachments
    • Attachment Handling
    • Multipart Form Data
Powered by GitBook
On this page
  • Scripted REST Service
  • Security Fields
  • Scripted REST Resource
  • Security Fields
  • Content Negotiation Fields
  • Update Process Record

Was this helpful?

Export as PDF
  1. Integration Guides
  2. Bidirectional Asynchronous Incident Guide

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.

PreviousProcessNextIntegration

Last updated 4 years ago

Was this helpful?

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.