LogoLogo
AboutSupport
4.2
4.2
  • Unifi User Documentation
  • Install
    • Release Notes
      • Unifi 4.2 Release Notes
      • Unifi 4.1 Release Notes
      • Unifi 4.0 Release Notes
      • Unifi 3.1 Release Notes
      • Unifi 3.0 Release Notes
      • Unifi 2.2 Release Notes
      • Unifi 2.1 Release Notes
      • Unifi 2.0 Release Notes
    • Install or Upgrade
      • Global Utility
      • Hotfix
  • Configure
    • Integration Designer
    • Processes
    • Integrations
    • Connections
    • Messages
    • Message Scripts
    • Fields
    • Field Maps
    • Response Actions
    • Event Actions
    • Datasets
      • Create a New Dataset
      • Dataset Extras
    • Polling
      • Pollers
      • Poll Processors
    • Administration
      • Activity Logs
      • Data Stores
      • Properties
      • Scheduled Scripts
      • System Logs
    • Attachments
      • Extracting Attachments
      • Fetching Attachments
      • Embedded Attachments
    • Scripting
      • Snippets
      • Variables
    • Documentation
    • How to guides
      • How to Handle Attachments
        • Message
        • Scripted REST Resource
        • Test AddAttachment
      • How to Manually Close a Bond
      • How to Poll for Large Response Payloads
      • How to Setup an OAuth Connection
        • Identity Provider Instance
        • Identity Consumer Instance
        • OAuth Refresh Token Job
      • How to Setup Heartbeat Messages
  • Deploy
    • Package
    • Instance Clone
  • Operate
    • Bonding
      • Bonds
      • Bonded Attachments
    • Transport
      • Snapshots
      • Transactions
      • Stages
      • HTTP Requests
      • Dataset Requests
      • Poll Requests
    • Error Handling
      • Integration Pause and Resume
      • Integration Repair
      • Request Retry
      • Transaction & Request Replay
      • Transaction Ignore
  • Test
    • Overview
    • Integration Test
    • Test Scenario
    • Test Scenario Data
    • Test Result
    • Test Scenario Result
    • Generating Tests
    • Running Tests
    • Exploring Results
  • Integration Guides
    • Outbound Incident Guide
      • Getting Started
      • Process
      • Integration
      • Connection
      • Create Scenario
        • CreateIncidentResponse Message
        • CreateIncidentResponse Fields
        • CreateIncident Message
        • CreateIncident Fields
        • Trigger
        • 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
      • Create Scenario
        • Response Message
        • CreateIncidentReceipt Message
        • CreateIncidentReceipt Fields
        • CreateIncident Message
        • CreateIncident Fields
        • Trigger
        • 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
  • Troubleshooting
    • Attachments
      • Inbound SOAP/Base64 attachments stopped working
      • New record attachments are not sent from Portal
      • Special characters in attachment file names
    • Datasets
    • Development
      • Bonding to existing records
      • Copying an existing Unifi trigger rule doesn't work
      • Duplicate messages being sent
      • Deleted records are not packaged
      • Multipart Form Data
      • Undefined error when building an integration
    • Diagnostic
    • Installation
      • Latest version of Unifi not accessible
    • Integration Responses
      • Transaction has been processed already
      • Initiating transaction not found for inbound receipt
      • Message has already been processed
      • Message ID not found
      • Message is not valid for this bond
      • Message name not recognised
      • No retry for requests with 401 response
      • Unable to identify message name from request
    • Other
      • Dynamic stage does not render
      • Duplicate bonds on Request integrations
    • Self-test
  • About
    • Quick Tour
    • Supported Features
    • Application Modules
    • Data Model
    • Transport Data Flow
Powered by GitBook
On this page
  • Copy Child Poll Processor
  • Copy Poll Processor Modal
  • Edit Copied Poll Processor
  • Response Script
  • Update Select Attachments Poll Processor

Was this helpful?

Export as PDF
  1. Integration Guides
  2. Incident Attachment Poller Guide
  3. Polling

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.

PreviousSelect Attachments PollerNextEdit Child Update Poller

Was this helpful?

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.

Copy Child Poll Processor

To copy the Child Poll processor, in Unifi Integration Designer, click the 'Poll Processors' Icon.

Copy Poll Processor Modal

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.

Edit Copied Poll Processor

The fields to edit for the Copied Poll Processor are as follows:

Field
Description
Value

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.

Response Script

The Response Script field is to be edited as follows:

Field
Description
Value

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:

// Process the response returned by the request script
// The 'answer' variable from the request script is passed in here as the 'response' parameter 
(function(poll_request, poller, response, params) {

    // DataStore name constant
    // Storage of time based High Water Marker
    var ATTACHMENT_HWM = 'attachment_hwm';

    var body = JSON.parse(response);

    // Nothing to do if no results were returned
    if (body.result.length == 0) {
        poll_request.response_status = 'No Incidents returned\n\n' + JSON.stringify(body, null, 2);
        return;
    }

    // Sample result (single Incident)
    /*
    {
      "result": {
        "sys_id": "0ecc4865db734010c3ebde82ca961960",
        "number": "INC0010107",
        "correlation_id": "INC0010345",
        "short_description": "Demo two - Fixing request",
        "description": "A long description",
        "state":"2",
        "sys_updated_on": "2020-04-02 14:00:00",
        "sys_updated_by": "a.user"
      }
    }    
    */

    // Establish the environment
    var integration = poller.getIntegration();
    var config = integration.getConfig();
    var conn = integration.getActiveConnection();
    var cvars = conn.getVariables();

    var poll_helper = new x_snd_eb.PollHelper(poll_request);
    var info = [];

    // Use Unifi code to find the Bond for an Incident
    function get_bond(inc) {
        var bond = new x_snd_eb.Bond(config);
        bond.locateReference(integration, inc.correlation_id, inc.sys_id);
        if (!bond.isValidRecord()) {
            return null;
        }
        return bond;
    }

    // Work out the message type to send to Unifi based upon the change of state
    function get_message_name(curr, prev) {

        // Default message type is an update
        var message_name = 'UpdateIncidentInbound';

        // Use the default type if we have no previous state
        if (!prev || !prev.state) {
            return message_name;
        }

        // Use the default type if there is no change in state
        if (curr.state == prev.state) {
            return message_name;
        }

        // We know the state has changed, check if it is Resolved (6)
        if (curr.state == '6') {
            message_name = 'ResolveIncidentInbound';
        }

        return message_name;
    }

    function execute_child_poller(inc, bond) {

        if (!bond) {
            return {};
        }

        // Set up a Poll to check for new attachments
        x_snd_eb.Poller.execute(cvars.select_attachments_poller, {
            int_ref: inc.correlation_id,
            ext_ref: inc.sys_id,
            attachment_hwm: bond.getData(ATTACHMENT_HWM, '')
        });

    }

    function process_incident(inc) {

        // Log the incident number and time
        var inc_time = inc.sys_updated_on;
        info.push('Incident : ' + inc.number + ' (' + inc_time + ')');

        // Find the bond on which the previous data is stored
        var bond = get_bond(inc);

        // If no bond was found, ignore this incident
        if (!bond) {
            info.push('- Bond not found - Incident ignored');
            return;
        }

        // Get the data stored for the incident by a previous poll
        var previous_inc = bond.getDataObject('previous_inc', {
            state: '2'
        });

        // Work out the message type to send into Unifi 
        var message_name = get_message_name(inc, previous_inc);
        info.push('- Message name: ' + message_name);

        // Set up the payload object for passing into Unifi
        var payload = {
            message: {
                name: message_name,
                source_reference: inc.sys_id
            },
            detail: {
                short_description: inc.short_description,
                description: inc.description,
                state: inc.state,
                close_code: inc.close_code,
                close_notes: inc.close_notes
            }
        };

        // Submit the message into Unifi
        poll_helper.processInbound({
            payload: JSON.stringify(payload)
        });

        // Check for Attachments
        execute_child_poller(inc, bond);

        // Save the current incident as the previous incident for the next poll
        bond.setDataObject('previous_inc', inc);

        // Update last update time (if later)
        var conn_time = conn.getData('last_update_time', '');
        if (inc_time > conn_time) {
            conn.setData('last_update_time', inc_time);
        }

    }

    // Process the single result
    process_incident(body.result);

    poll_request.response_status = info.join('\n') + '\n\n' + JSON.stringify(body, null, 2);

})(poll_request, poller, response, params);

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:

    var ATTACHMENT_HWM = 'attachment_hwm';

This is a DataStore name constant to store a time based high water mark.

 function execute_child_poller(inc, bond) {
 
         if (!bond) {
             return {};
         }
 
         // Set up a Poll to check for new attachments
         x_snd_eb.Poller.execute(cvars.select_attachments_poller, {
             int_ref: inc.correlation_id,
             ext_ref: inc.sys_id,
             attachment_hwm: bond.getData(ATTACHMENT_HWM, '')
         });
 
     }
        execute_child_poller(inc, bond);

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.

Update Select Attachments 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).

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.

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.

Incident Parent and Child Poller Guide
Select Attachments Poller
Select Attachments Poll Processor'