The final configuration step on the ServiceNow side for your Freshservice service integration is to add a script action. 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 an 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 your Freshservice instance.

Prerequisites


(warning) You will first need to create a dynamic share for Freshservice.

(warning) You will also need to create custom table map fields for Freshservice and update required transform map field scripts for Freshservice.

Procedure


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

1. 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.

2. Click New to create a new script action.

3. In the resulting Script Action form, type Perspectium Attachment (Freshservice) as the Name. Then, select attachment.uploaded from the Event name dropdown.

4. Check the Active box. Then, add the following script in the scripting window:

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, "freshservice_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.siam.client.freshservice");
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, 'freshservice_sent');
}
}


5. Click Submit to finish creating your script action.