ServiceNow script actions are server-side scripts triggered by events that can modify configuration items in your instance. The script action that you will need to add will create a ServiceNow outbound message for any incident records that have attachment data included, thus ensuring that any attachments you have created in ServiceNow are successfully shared out to Ivanti Service Manager.


Prerequisites


(warning) First, you will need to create a ServiceNow dynamic share for Ivanti.

(warning) You will also need to create a ServiceNow subscribed queue and subscribe for Ivanti and edit ServiceNow outbound table map fields for Ivanti.

(warning) Lastly, you will need to add and edit ServiceNow transform map scripts for Ivanti.

Procedure

To add a ServiceNow attachment.uploaded script action for Ivanti, follow these steps:


Create a new script action

Log into your ServiceNow instance and navigate to System Policy > Events > Script Actions or simply type and then select Script Actions in the Filter Navigator on the upper left-hand side of the screen. Then, click New to create a new script action.

Add an attachment.uploaded script

In the resulting Script Action form, type Perspectium Attachment (Ivanti) as the Name. Then, select attachment.uploaded from the Event name dropdown. Check the Active box. Then, add the script shown below in the scripting window and click Submit in the bottom left-hand corner of the form to save your script action.

pspShareUploaded();
function pspShareUploaded() {
    var pspRepl = new PerspectiumReplicator();
    var pspUtil = new PerspectiumUtil();
    var tableName = event.parm1;
    var tableSysId = event.parm2;
    var tgr = new GlideRecord(tableName);
    tgr.addQuery('sys_id', tableSysId);
    tgr.queryNoDomain();
    if (!tgr.next()) {
        return;
    }
    var op = "attach";
    var agr = new GlideRecord(event.table);
    agr.get(event.instance);
    if (pspUtil.recordHasTag(agr, "ivanti_sent")) {
        return;
    }
    var qc = new GlideRecord('psp_replicate_conf');
    qc.addQuery('table_name', tableName);
    qc.addQuery('action_create', true);
    qc.addQuery("action_update", true);
    qc.addQuery("sync_direction", "share");
    qc.addQuery("active", "true");
    qc.addQuery("u_target_queue.u_name", "psp.in.meshlet.ivanti");
    qc.query();
    while(qc.next()) { 
        // reset the message set counter each time we do a new share configuration
        pspRepl.messageSetCounter = {};
            var startedDateTime = gs.nowDateTime();
            // share record, setting tag to mark attachments
            if (tgr.operation() == "insert" || (tgr.isValidField("correlation_id") && tgr.correlation_id.nil())) {
                op = "deferred";
            }
           // try changing name from update to attach
            pspRepl.shareOneRecord(tgr, qc, tableName, op, 'ivanti_sent'); 
        }
    }