ServiceNow transform maps allow you to map data from an import set table (inbound data for ServiceNow) to fields in the appropriate ServiceNow tables. To ensure that data being shared out of Salesforce and into your ServiceNow instance is mapped to the proper fields, you will need to make some changes to the existing PSP Common Incident to Incident transform map in your ServiceNow instance that will be used as the hub for your multi-app ServiceBond integration.


Procedure

To modify the PSP Common Incident to Incident transform map in ServiceNow for your multi-app ServiceBond integration, follow these steps:


Access and rename the PSP Common Incident to Incident transform map 

Log into your ServiceNow instance and navigate to Perspectium Common DocumentsPSP Common Transform Maps. Click into the PSP Common Incident to Incident transform map and click Copy in the upper right-hand corner of the form to copy the transform map. Then, click into the copied table map and rename it to PSP Common Incident to Incident (Salesforce) and click Update to save your changes.

Access field maps

Make sure that the Run business rules box is checked. Then, scroll down to the Field Maps tab. 

Add a source script to the sys_id field map

Within the list of field maps, locate and then click into the field map with a target field of sys_id. Then, add the following Source script:

answer = (function transformEntry(source) {
    var pspC = new PerspectiumCorrelation();
    return pspC.getRecordSysId(source, 'salesforce', 'incident');
})(source);

Finally, click Update in the bottom left-hand corner of the form to save your changes. 

Update transform scripts

Scroll down and click the Transform Scripts tab. Edit two transform scripts by clicking into them and using the updated scripts as follows (Be sure to click Update to save your changes to each transform script):

Script begins withUpdated script
//comments
//comments - Prevent looping when comments are posted
(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {

    var pspUtil = new PerspectiumUtil();
    var elementId = target.sys_id;

    if (source.u_comments.nil())
        return;

    var tgr = new GlideRecord("sys_journal_field");
    tgr.addQuery("element_id", elementId);
    tgr.orderByDesc("sys_created_on");
    tgr.query();
    if (tgr.next()) {
        if (pspUtil.recordHasTag(tgr, "salesforce_sent")) {
            return;
        }
        pspUtil.addTag(tgr, "salesforce_sent");
    }

})(source, map, log, target);
//deferred 
//deferred - Reprocess messages that has not been e-bonded
(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
var igr = new GlideRecord("incident");
igr.addQuery("sys_id", source.sys_target_sys_id);
igr.query();

var ogr = new GlideRecord("psp_out_message");
var pspS = new PerspectiumEncryption();
ogr.addQuery("state", "Deferred");
ogr.addQuery("u_extra", 'CONTAINS', "number=" + igr.number);
ogr.addQuery("u_target_queue.u_name", "psp.in.siam.client.salesforce");
ogr.queryNoDomain();

while (ogr.next()) {
var att = ogr.u_attributes.toString();
if (att.indexOf(target.sys_id) < 0)
continue;

var cipher;
if (ogr.u_attributes.includes("cipher=3"))
cipher = "3";
else
cipher = "2";

var decodeData = pspS.decryptString(ogr.value);
decodeData = decodeData.replace("<correlation_id/>", "<correlation_id>" + source.u_sys_id + "</correlation_id>");
decodeData = decodeData.replace("<correlation_display/>", "<correlation_display>" + source.u_number + "</correlation_display>");

var name;
if (decodeData.includes("</comments>"))
name = "common_incident.comment";
else if (decodeData.includes("</attachment>"))
name = "common_incident.attachment";
else
name = "common_incident.insert";

ogr.name = name;
ogr.u_extra = "";
ogr.state = "ready";
ogr.value = pspS.encryptStringWithCipher(decodeData, cipher);
ogr.update();
}
})(source, map, log, target);

  

Add transform scripts

Create three new transform scripts by clicking New and adding the following specifications for each (Be sure to click Submit to save each new transform script):

WhenActive checked?OrderScript
onBeforeYes90
// Ignore apps other than Salesforce
(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {

    if (!source.u_provider.toString().contains("salesforce")) {
        ignore = true;
    }

})(source, map, log, target);
onAfterYes90
// Update correlation IDs in the Correlation table
(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {

    if (source.u_provider.toString().contains("salesforce")) {
        var pspC = new PerspectiumCorrelation();
        pspC.updateCorrelationRecord(target, source, 'salesforce');
    }

})(source, map, log, target);
onBeforeYes105
// Prevent duplication of comments
(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {

    if (source.u_comments.nil())
        return;
    var sgr = new GlideRecord("sys_journal_field");
    sgr.addQuery("name", target.getTableName());
    sgr.addQuery("element", "comments");
    sgr.addQuery("element_id", target.sys_id);
    sgr.addQuery("value", source.u_comments);
    sgr.query();
    if (sgr.next())
        ignore = true;

})(source, map, log, target);

Save the PSP Common Incident to Incident (Salesforce) transform map

Click Update in the top right-hand corner of the transform map form to save your changes to the PSP Common Incident to Incident (Salesforce) transform map.

Next steps


Modify the Common Incident to Incident for Jira transform map in ServiceNow (multi-app integration)