We will configure a scheduled poll to query the remote system at regular intervals and pull back data that has changed which it will pass to Unifi to process.
To set up a scheduled poll that will query the remote system at regular intervals, check whether any data has changed and then pass that data to Unifi, we will need to configure the following records:
Poll Processor
Poller
Once those records are configured, we will need to configure inbound Messages to process the returned data. We will look at the polling records in turn over the next couple of pages.
We're now ready to configure the Poll Processor.
A Poller is a configuration record which defines the frequency of polling and which logic to use.
A Poller is a configuration record which defines the frequency of polling and which logic to use (the logic itself is defined in the Poll Processor). Each time it is run, it creates a corresponding Poll Request record.
Rather than create a new poller, you can edit the previously configured 'Update Poller', changing the Name, Description & Poll Processor.
(You could choose to copy the previous Poller instead. However, there is no need to have two pollers polling for updates every 5 minutes, so if copying the previous poller, remember to deactivate it.)
1) Click to open the previously configured Incident Update Poller.
The fields to be edited for our Poller record are as follows:
*These fields are mandatory, or automatically defaulted to true.
Your Multiple Message Poller should look like this:
5) Save the Poller.
In order to process the inbound Requests, we need to configure the Inbound Messages.
#
Field
Description
Value
2*
Name
The name of your Poller.
<Your Name>
3
Description
A description of what this Poller is for and/or how it works.
<Your Description>
4*
Poll processor
The Poll Processor to use when running this Poller.
<Your Poll Processor> (the one just created)
The Poll Processor contains the logic that will be applied when polling a remote system for data.
The Poll Processor is a configuration record which contains the logic that will be applied when polling a remote system for data. There are three main scripts which are used to setup, execute and process the Poll Requests. The scripts given here are examples of how you might configure your Poll. The details of yours may differ depending on your requirements.
Before continuing we would again like to remind you of the relevant icons that are visible down the left hand navigation strip of the Unifi Integration Designer.
The icons are:
a) 'Integration' icon: Opens the current integration's Details page.
b) 'Messages' icon: Opens the current integration's Messages page.
c) 'Fields' icon: Opens the current integration's Fields page.
d) 'Field Maps' icon: Opens the current integration's Field Maps page.
e) 'Pollers' icon: Opens the current integration's Pollers page.
f) 'Poll Processors' icon: Opens the current integration's Poll Processors page.
In Unifi Integration Designer, navigate to & open < Your Integration > (created following the Outbound Incident Guide & Incident Update Poller Guide).
Click the 'Poll Processors' icon & then New.
The fields to be configured for the New Poll Processor modal are as follows:
Your New Poll Processor modal should look like this:
2) Submit and view to further configure the Poll Processor.
The Setup Script is the first script to run (it runs at the point in time the Poll Request is created). It is used to build the environment for the poll and define what it will do. We will use it to setup the URL that will be called.
Navigate to Scripts > Setup Script.
The initial Poll Processor fields to be configured are as follows:
The code in the Setup script field should look like this:
Setup script: The parameters for which data to return are contained in the endpoint url.
fields: The table API will return all the data by default, so we choose to deliberately limit what is returned to the fields listed in this variable.
query: Instead of querying all the records on the remote instance, we deliberately limit the records to those where the correlation id is not empty (i.e. it's bonded), that haven't been updated by the Authentication user (our system) and that were updated since either since the last update time (if one exists), or in the last 30 minutes.
Endpoint URL: The value used in the poll_request.endpoint_url was initially generated using the ServiceNow REST API Explorer, substituting variables in for the uri query and fields. This value is appended to the existing endpoint url in the active connection before being added to the Poll Request.
Note: We have included the /table/incident
element of the endpoint url because we used the truncated url in the Connection when following the Outbound Incident Guide. If you have used the full url there, then this element can be excluded here.
(We have also chosen to limit the number of records returned to 10.)
params: The params
object is passed through to the subsequent scripts (and on to further Pollers, if required).
Your Setup Script form should look like this:
4) Navigate to Request Script.
The Request Script is used to reach into the remote system and execute the request. We will use the ServiceNow RESTMessageV2() web service to make a REST call to the URL defined in the Setup Script.
The next Poll Processor field to be configured is as follows:
The code in the Request script field should look like this:
Request script: This script uses the ServiceNow RESTMessageV2() web service to make a REST call to the endpoint url created in the Setup script. It returns the body of the request as the answer which it passes to the Response script
Your Request Script form should look like this:
6) Navigate to Response Script.
The Response Script is used to process the information returned from the remote system. We will pass this data to Unifi, telling it which Message to use to process the data.
The last Poll Processor field to be configured is as follows:
The code in the Response script field should look like this:
Response script: This script parses the response into a body object to contain the result, (returning if it doesn't contain anything).
It then sets up some objects to help us; these include the essential PollHelper() function (which we initialise from the poll_request) along with two other functions: get_bond() to find the Bond for an Incident & get_message_name() to work out the message type to send to Unifi based upon the change of state.
After that it loops through each of the returned tickets. For each ticket, it logs the incident number & time, finds the bond & returns any previous data stored on the bond, decides which Message to use, sets up a payload object and submits it to Unifi by calling the processInbound() method. It then saves the current incident as the previous incident for the next poll & checks whether the ticket was updated later than the last update time; if so, it sets and stores the last update time as that 'sys_updated_on' value (this 'last_update_time' is what the Setup script checks against when defining what the Poll will do).
After looping through all the records (processing each result), the results are logged to the Response status field of the Poll Request.
Essential code: the following lines of code must be included in the response script to enable Unifi
processInbound(): Having the 'poll_helper.processInbound()' function inside the loop means that an update message will be generated for each updated ticket.
Payload object: We have chosen to structure the payload object (var payload
) as we have. There is no obligation to keep the same structure. Yours can be defined to suit your requirements.
Message name: Unifi needs to know the message name in order to know how to process the inbound request. We can either set it in the payload (as we have), or declare a variable that sets it which is passed into the processInbound() function along with the payload. (Unifi will always check processInbound() first. If no Message name is set here it will use the 'Identify message script' on the Integration).
Your Response Script form should look like this:
8) Save the Poll Processor.
Now let's move on and configure the Poller.
#
Field
Description
Value
1
Name
The name of the Processor.
<Your Name>
#
Field
Description
Value
3
Setup script
The script to setup the Poll Request record.
Update the code in the Setup script field so that it looks like the code below
#
Field
Description
Value
5
Request script
The script that executes the request.
Update the code in the Request script field so that it looks like the code below
#
Field
Description
Value
7
Response script
The script that processes the response to the request.
Update the code in the Response script field so that it looks like the code below