Edit Child Poll Processor
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.
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.
Click the ellipsis to the right of < Your Child Poll Processor > (created following the Incident Parent and Child Poller Guide) & then click Copy.
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
The name of the Processor.
<Your Name>*
*Name: We've chosen to append the existing value with, "(with Attachments)".
Your Copied Poll Processor should look like this:
Navigate to Scripts > Response Script.
The Response Script field is to be edited as follows:
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
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.
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 'Select Attachments Poller' 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).
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:
Click Save.
Navigate to and open the Select Attachments Poll Processor (created on the 'Select Attachments Poll Processor' page) and update the value of the Parent field by selecting its parent Poll Processor created above.
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.