Script actions are server-side scripts triggered by events that can modify configuration items in your ServiceNow instance. The script action that you will need to edit in this step will create an outbound message for any incident records that have attachment or comment (work notes) data included, thus ensuring that any attachments and comments you have created in ServiceNow are successfully shared out to your Salesforce org.


Procedure

To edit the Salesforce Share Comment and Salesforce Share Attachment script actions in ServiceNow for a multi-app ServiceBond integration, follow these steps:


Navigate to Script Actions

Log into your ServiceNow instance and navigate to System PolicyEventsScript Actions

Update the Salesforce Share Comment script action

Click into the Salesforce Share Comment script action with an event name of incident.commented. Then, update the script as follows:

pspShareUploaded();

function pspShareUploaded() {
var pspRepl = new PerspectiumReplicator();
var pspUtil = new PerspectiumUtil();
var tableName = event.table;
var tableSysId = event.instance;
var tgr = new GlideRecord(tableName);
tgr.addQuery('sys_id', tableSysId);
tgr.queryNoDomain();
if (!tgr.next()) {
return;
}

var sgr = new GlideRecord("sys_journal_field");
sgr.addQuery("element_id", tableSysId);
sgr.orderByDesc("sys_created_on");
sgr.query();
if (!sgr.next()) {
return;
}

if (pspUtil.recordHasTag(sgr, "salesforce_sent"))
return;
tgr.comments = sgr.value.toString();

var op = "comment";
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.salesforce");
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 comments
var pspC = new PerspectiumCorrelation();
var cgr =  pspC.getCorrelationRecord(tgr, '', 'salesforce');
if (tgr.operation() == "insert" || (cgr == null || cgr.u_correlation_id == '')) {
op = "deferred";
}
// try changing name from update to comment
pspRepl.shareOneRecord(tgr, qc, tableName, op, 'salesforce_sent');
}

}

Then, click Update in the bottom left-hand corner of the form to save the changes to this script action.

(info) NOTE: The Salesforce Share Comment script action should have been initially set up when enabling the sharing of attachments and comments from ServiceNow to Salesforce.

Update the Salesforce Share Attachment script action

Click into the Salesforce Share Attachment script action with an event name of attachment.uploaded. Then, update the script as follows:

pspShareUploaded();

function pspShareUploaded() {
var pspRepl = new PerspectiumReplicator();
var pspUtil = new PerspectiumUtil();
var pspCor = new PerspectiumCorrelation();

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 = "attachment";

var agr = new GlideRecord(event.table);
agr.get(event.instance);
if (pspUtil.recordHasTag(agr, "salesforce_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.salesforce");
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

var cgr =  pspCor.getCorrelationRecord(tgr, '', 'salesforce');
if (tgr.operation() == "insert" || cgr == null || (cgr && cgr.u_correlation_id == '')) {
op = "deferred";
}
// try changing name from update to attach

pspRepl.shareOneRecord(tgr, qc, tableName, op, 'salesforce_sent');
}
}

Then, click Update in the bottom left-hand corner of the form to save the changes to this script action.

(info) NOTE: The Salesforce Share Attachment script action should have been initially set up when enabling the sharing of attachments and comments from ServiceNow to Salesforce.

Next steps


Edit the Perspectium synchronize Jira attachment script action in ServiceNow