Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
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.
Click the 'Pollers' icon & then New.
The fields to be configured for our Poller record are as follows:
*These fields are mandatory, or automatically defaulted to true.
Your New Poller modal should look like this:
5) Submit and view to further configure the Poller.
The fields to be configured for the Details form are as follows:
Your Details form should look like this:
7) Save the Poller.
Update the value of the 'get_attachment_poller' Connection Variable with the sys_id.
8) Click on the Hamburger Menu and select Open in platform.
The Poller opens in a new window.
9) Right-click the Header & 'Copy sys_id'.
Open the variable created on the 'Connection Variables' page of this Guide and update the value with the copied sys_id.
Next, we will configure the Select Attachments Poll Processor.
#
Field
Description
Value
6
Description
A description of what this Poller is for and/or how it works.
<Your description>
#
Field
Description
Value
1*
Name
The name of your Poller.
<Your Name>
2*
Poll processor
The Poll Processor to use when running this Poller.
<Your Poll Processor>
3
Run
The frequency at which the Poller should run.
'On Demand'
4
Run as
Poller will run with credentials of specified user.
<Your Inbound user> (from Connection)
*
Active
Set to true to use this Poller record for processing.
<true>
We have previously been polling the Table API of our PDI. We now want to poll the Attachment API. To facilitate this, we will need to make changes to the Endpoint URLs in multiple places.
The instructions on this page only apply if you have configured the Connection with the full endpoint url (including the /table/incident
element).
If you have used the truncated url in the Connection (moving the /table/incident
element to the outbound Message path & Poll Processors), this page may be skipped.
To facilitate polling both the Table API and Attachment API, we will need to edit the Endpoint URLs configured in earlier Guides in the following places:
Connection
Outbound Message Path
Previously Configured Poll Processors
First, edit the Endpoint URL in the Connection.
In Unifi Integration Designer, navigate to the 'Connections' icon. Click to open & edit < Your Connection > (configured following the Outbound Incident Guide).
Remove /table/incident
from the Endpoint URL and Save. (This will be prepended to the Outbound Message Path & previously configured Poll Processors.)
Edit each of the previously configured Outbound Messages:
CreateIncident
UpdateIncident
ResolvIncident
CreateIncidentInboundReceipt
To edit the CreateIncident Message, navigate to the 'Messages' icon & click to open the CreateIncident Message.
Navigate to Outbound > Settings. Add the previously cut /table/incident
to the Path & Save.
Repeat for each of the other Outbound Messages.
DO NOT delete the existing path, rather prepend it with /table/incident
(as cut from the Connection). For example, the Path for the UpdateIncident Message should now read as follows: /table/incident/{bond.getValue("external_reference")}
.
Edit the Endpoint URL in the Setup script for each of the previously configured Poll Processors:*
*(The names of your Poll Processors may differ.)
Unifi - SN REST Poll Processor (as configured in the 'Poll Processor' page of the Incident Update Poller Guide
Unifi - SN REST Poller with Incident DataStore (as configured in the 'Poll Processor' page of the Incident Multiple Message Poller Guide)
Unifi - SN REST Create Poll processor (as configured in the 'Poll Processor' page of the Incident Create Poller Guide)
Unifi - SN REST Poller Single incident (as configured in the 'Child Poll Processor' page of the Incident Parent and Child Poller Guide)
Unifi - SN REST Poller Incident List (as configured in the 'Parent Poll Processor' page of the Incident Parent and Child Poller Guide)
Note: Although it is necessary to edit the Endpoint URL for all of the previously configured Poll Processors for each of them to work, it is only essential (for the purposes of this Guide) that this is done for the Parent and Child Poll Processors and the Create Poll Processor as these will be used when testing our Integration (& the Messages).
To edit the Unifi - SN REST Poll Processor, navigate to the 'Poll Processors' icon & click to open the Unifi - SN REST Poll Processor.
Navigate to Scripts > Setup Script.
Edit the code by prepending the existing Endpoint URL with /table/incident
i.e. insert it immediately after the poll_request.endpoint_url += '
value & click Save. That line of code should now read as follows:
Your Unifi - SN REST Poll Processor Setup Script should now look like this:
Repeat for each of the other previously configured Poll Processors.
Once complete we can configure the first of our Child Poll Processors, the Get Attachment Poll Processor.
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.
This Get Attachment Poll Processor will take take each record passed to it from its parent - Select Attachments Poll Processor - and then make a Poll Request against that record, retrieving the attachment, building a payload and passing it to Unifi to process.
In Unifi Integration Designer, navigate to & open < Your Integration > (created following the Outbound Incident Guide).
Click the 'Poll Processors' icon & then New.
The fields to be configured for the New Poll Processor modal are as follows:
*Run parallel: Each Poll Request will have different input parameters (i.e. the sys_id of one of the attachments passed from its Parent). We can therefore run concurrent Poll Requests on the different records without concern for overlap issues.
Your New Poll Processor modal should look like this:
3) 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.
Endpoint URL: The value used in the poll_request.endpoint_url was initially generated using the ServiceNow REST API Explorer polling the Attachment API, substituting a variable in for the sys_id of a specific attachment to query. This value is appended to the existing endpoint url in the active connection before being added to the Poll Request.
params: The params
object is passed through to the subsequent scripts (and on to further Pollers, if required). This script has been passed the sys_id of a specific attachment from its parent Poller.
Your Setup Script form should look like this:
5) 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 an attachment who's sys_id it passes to the Response script
saveResponseBodyAsAttachment(): This method takes three parameters:
tableName - the table that contains the record you want to attach the saved file to.
recordSysId - the sys_id of the record you want to attach the saved file to.
fileName - the file name to give to the saved file.
request.execute(): The response object returned by request.execute() provides a method called getResponseAttachmentSysid().
getResponseAttachmentSysid(): This method returns the sys_id
of the attachment generated by the REST call.
Your Request Script form should look like this:
7) 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 sets up some objects to help us; this includes the essential PollHelper() function (which we initialise from the poll_request) along with the info [] array.
After that it sets params.attachment.data to the sys_id of the created attachment, setting up a payload object and submitting it to Unifi by calling the processInbound() method.
After processing the single result, it is 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
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 did in previous Guides), or declare a variable that sets it which is passed into the processInbound() function along with the payload (as we have here). (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:
9) Save the Poll Processor.
Now let's move on and configure the Get Attachment Poller.
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.
Click the 'Pollers' icon & then New.
The fields to be configured for our Poller record are as follows:
*These fields are mandatory, or automatically defaulted to true.
Your New Poller modal should look like this:
5) Submit and view to further configure the Poller.
The fields to be configured for the Details form are as follows:
Your Details form should look like this:
7) Save the Poller.
Update the value of the 'select_attachments' Connection Variable with the sys_id of the child Poller.
8) Click on the Hamburger Menu and select Open in platform.
The Poller opens in a new window.
9) Right-click the Header & 'Copy sys_id'.
Next, we will edit our previously configured Child Poll Processor so that it becomes the parent of this.
Our previously configured Child Poll Processor only polled for updates against records passed to it from its Parent. We will now edit it so that it will also kick off the Select Attachments Poller.
Rather than just making edits to the existing Child Poll Processor, we will instead copy it & edit the copy. That way we will have one Child Poll Processor that just polls for updates and another that polls for updates and attachments.
To copy the Child Poll processor, in Unifi Integration Designer, click the 'Poll Processors' Icon.
2) Click Copy.
Your Copy Poll Processor modal should look like this:
You will be redirected to the Details page of the newly copied Poll Processor.
The fields to edit for the Copied Poll Processor are as follows:
*Name: We've chosen to append the existing value with, "(with Attachments)".
Your Copied Poll Processor should look like this:
4) Navigate to Scripts > Response Script.
The Response Script field is to be edited as follows:
The code in the Response script field should look like this:
Response script: This script creates a variable to store a time based high water marker and parses the response into a body object to contain the result, (returning if it doesn't contain anything).
It then establishes the environment, getting the Integration, Configuration, Connection & Connection Variables and sets up the essential PollHelper() function (which we initialise from the poll_request) along with the info [] array.
After that it sets up some other functions: get_bond()
finds the bond for the Incident (returning if there isn't one), get_message_name()
works out the message type to send to Unifi based upon the change of state & execute_child_poller()
sets up a Poll Request to check for new attachments.
It then processes each of the results (passed in tickets). For each, it logs the incident number & time, finding the bond & returning any previous data stored on the bond, deciding which Message to use, setting up a payload object and submitting it to Unifi by calling the processInbound()
method. It then runs the execute_child_poller()
function and 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).
On processing each result, it is then logged to the Response status field of the Poll Request.
params: The params
object is passed through to the subsequent scripts (and on to further Pollers, if required). This is used to pass the int_ref, ext_ref & attachment_hwm elements to the child Poller.
Code Edits - The following code snippets were added to the existing codebase to facilitate polling for attachments:
This is a DataStore name constant to store a time based high water mark.
Causing the execute_child_poller() function to run (as set up above) - passing in the Incident & Bond.
Your Response Script form should look like this:
6) Click Save.
Remember, We have not scripted any business logic to run from the value in the Parent field. It is given for documentary purposes only (for you to easily identify which parent Poll Processor kicked off the child).
The following Poll Processors should now be in place on the Integration:
We could Deactivate the copied "Unifi - SN REST Poller Single Incident" now that we've created this version, "with Attachments". However, we will instead edit the Child Update Poller that runs it.
Now let's move on and edit the Child Update Poller (configured when following the Incident Parent and Child Poller Guide) so that it runs the Poll Processor created above.
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.
This Select Attachments Poll Processor will pull back a list of the relevant attachment records. Each record it identifies will be passed on to its child - Get Attachment Poll Processor.
In Unifi Integration Designer, navigate to & open < Your Integration > (created following the Outbound Incident 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.
query: Instead of querying all the attachments on the remote instance, we deliberately limit the query to those where the table_sys_id (target record) is the sys_id of a bonded Incident (passed in from the Response script of its Parent Poll Processor), that haven't been updated by the Authentication user (our system) and that were updated 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 a variable in for the uri query. This value is appended to the existing endpoint url in the active connection before being added to the Poll Request.
(We have also chosen to limit the number of records returned to 10.)
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 use it to build an attachment object to pass this data to the next Poll Processor.
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 creates a variable to store a time based high water marker and parses the response into a body object to contain the result, (returning if it doesn't contain anything).
It then establishes the environment, getting the Integration, Connection & Connection Variables and sets up the essential PollHelper() function (which we initialise from the poll_request) along with the info [] array.
After that it finds the bond for the Incident (returning if there isn't one) & then processes each of the results (returned attachment records). For each, it builds an attachment object and sets up a Poll Request to retrieve & process the remote attachment (returning a PollRequest object). It also tracks the latest sys_created_on time.
After processing each result, the script checks whether the attachment was created later than the latest attachment high water mark; if so, it sets and stores that 'sys_created_on' value as the attachment high water mark (the 'attachment_hwm' is what the Setup script checks against when defining what the Poll will do). The results are then logged to the Response status field of the Poll Request.
params: The params
object is passed through to the subsequent scripts (and on to further Pollers, if required). This is used to pass the int_ref, ext_ref & attachment elements to the child Poller.
Your Response Script form should look like this:
8) Save the Poll Processor.
Remember, We have not scripted any business logic to run from the value in the Parent field. It is given for documentary purposes only (for you to easily identify which parent Poll Processor kicked off the child).
Now let's move on and configure the Select Attachments Poller.
Connection Variables can be especially useful if you have multiple connection environments - e.g. Dev, Test, Prod - each containing different data.
Although having multiple environments may not apply to this integration, we will create Connection Variables to contain certain data values which will be substituted into the Poll Processor scripts.
Instead of scripting data values directly into the code of your Poll Processor scripts, it may be better practice to use Connection Variables in their place. Not only does it make those scripts cleaner, but it also means that changes in requirements can be more easily enacted by changing the values of the data in those variables, without having to change the code in the scripts.
We will create an additional two Connection Variables to identify the Child Pollers we shall be creating.
Before continuing we would like to draw your attention to some of the relevant icons that will be visible down the left hand navigation strip in Unifi Integration Designer.
The icons are:
a) 'Integration' icon: Opens the current integration's Details page.
b) 'Pollers' icon: Opens the current integration's Pollers page.
c) 'Poll Processors' icon: Opens the current integration's Poll Processors page.
d) 'Connections' icon: Opens the current integration's Connections page.
To open Unifi Integration Designer, navigate to Unifi > Unifi Integration Designer, then navigate to < Your Integration > (created following the Outbound Incident Guide).
Click the 'Connections' icon, then navigate to and open < Your Connection >.
From the Connection, navigate to Connection > Variables & click New.
The 'get_attachment_poller' New Connection Variable fields to be configured are as follows:
*Value may vary. Use the sys_id of the Poller you will create from the Get Attachment Poller page.
Your 'get_attachment_poller' New Connection Variable modal should look like this:
4) Click Submit.
You will be redirected back to the Variables page of the Connection record.
From the Connection, navigate to Connection > Variables & click New.
The 'select_attachments_poller' New Connection Variable fields to be configured are as follows:
*Value may vary. Use the sys_id of the Poller you will create from the Select Attachments Poller.
Your 'select_attachments_poller' New Connection Variable modal should look like this:
8) Click Submit.
The following Connection Variables should now be in place for your Connection:
Now let's move on and edit the Endpoint URLs.
'Parent' - Once we have created its , we can then select it here. We have not scripted any business logic to run from the value in this field. It is given for documentary purposes only.
Open the variable created on the '' page of this Guide and update the value with the copied sys_id.
1) Click the ellipsis to the right of < Your Child Poll Processor > (created following the ) & then click Copy.
The x_snd_eb.Poller.execute() method has two parameters. In the first we pass the sys_id of the child Poller (as created on the '' page). In the second we pass an object containing the correlation_id on the bonded Incident as the int_ref element, the sys_id of the bonded Incident as the ext_ref element and the value of the ATTACHMENT_HWM DataStore as the attachment_hwm element (telling the child Poller which attachment records to poll).
Navigate to and open the Select Attachments Poll Processor (created on the ' page) and update the value of the Parent field by selecting its parent Poll Processor created above.
'Parent' - Once we have created its , we can then select it here. We have not scripted any business logic to run from the value in this field. It is given for documentary purposes only.
x_snd_eb.Poller.execute(): This method has two parameters. In the first we pass the sys_id of the child Poller (as created in the '' page). In the second we pass an object containing the correlation_id on the bonded Incident as the int_ref element, the sys_id of the bonded Incident as the ext_ref element and the attachment object as the attachment element (telling the child Poller which attachment record to poll).
Navigate to and open the Get Attachment Poll Processor (created on the '' page) and update the value of the Parent field by selecting its parent Poll Processor created above.
This variable will contain the sys_id of the child Poller which we will create on the '' page of this Guide. Once you have created the Poller, copy the sys_id and paste it as the value in this variable.
This variable will contain the sys_id of the child Poller which we will create on the '' page of this Guide. Once you have created the Poller, copy the sys_id and paste it as the value in this variable.
# | Field | Description | Value |
4 | 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 |
6 | 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 |
8 | 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 |
# | Field | Description | Value |
6 | Description | A description of what this Poller is for and/or how it works. | <Your description> |
# | Field | Description | Value |
3 | Name | The name of the Processor. | <Your Name>* |
# | Field | Description | Value |
5 | 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 |
# | 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 |
# | Field | Description | Value |
1 | Key | A unique name that will be used to get the value. | 'get_attachment_poller' |
2 | Value | The variable value to be used in the integration. | <Your Value>* |
3 | Description | Describe what this connection variable is for and how it should be used. | <Your Description> |
# | Field | Description | Value |
5 | Key | A unique name that will be used to get the value. | 'select_attachments_poller' |
6 | Value | The variable value to be used in the integration. | <Your Value>* |
7 | Description | Describe what this connection variable is for and how it should be used. | <Your Description> |
# | Field | Description | Value |
1 | Name | The name of the Processor. | <Your Name> |
2 | Run parallel | Allow concurrent Poll Requests to be executed. | <true>* |
# | Field | Description | Value |
1* | Name | The name of your Poller. | <Your Name> |
2* | Poll processor | The Poll Processor to use when running this Poller. | <Your Poll Processor> |
3 | Run | The frequency at which the Poller should run. | 'On Demand' |
4 | Run as | Poller will run with credentials of specified user. | <Your Inbound user> (from Connetion) |
* | Active | Set to true to use this Poller record for processing. | <true> |
# | Field | Description | Value |
1 | Name | The name of the Processor. | <Your Name> |
We will configure an on-demand poll to query the remote system and pull back a list of attachments added to bonded records that have changed. Each will then be retrieved by another on-demand poll.
To set up an on-demand poll that will query the remote system for attachments and pass each to a subsequent poll, which will then retrieve them and pass them to Unifi to process, we will need to configure a further two each of the following records:
Child Poll Processor
Child Poller
(Note: one of the children will be a parent to the other)
We will also need to edit the previously configured Child Poll Processor (per the Parent & Child Poller Guide) to kick-off the first of our attachment Child Pollers.
To facilitate polling both the Table API and Attachment API, we may also need to make changes to the Endpoint URLs* configured in earlier Guides in the following places: (*only if the Connection contains the full endpoint url)
Connection
Outbound Message Path
Poll Processor Setup Script
We will look at each of those edits and the polling records in turn over subsequent pages. Before configuring those records, let’s first look at Connection Variables.
A Poller is a configuration record which defines the frequency of polling and which logic to use.
We will edit the previously created Child Update Poller, so that it runs our new "Unifi - SN REST Poller Single Incident with Attachments" (as created in the previous section) instead of the originally configured Poll Processor.
To edit the Child update Poller, click the 'Pollers' icon.
Click to open < Your Child Update Poller > (created following the Incident Parent and Child Poller Guide)
The fields to be edited for the Details form are as follows:
*Poll Processor: Value may vary. Choose the Poll Processor you created in the previous section.
Your Details form should look like this:
3) Save the Poller.
In the next section, we will look at the Inbound Messages.
#
Field
Description
Value
1
Poll processor
The Poll Processor to use when running this Poller.
<Your Poll Processor>*
2
Description
A description of what this Poller is for and/or how it works.
<Your Description> (edit accordingly)