After creating a ServiceNow dynamic share for Freshdesk and creating custom ServiceNow outbound table map fields, you will next need to update the scripts for several fields in the PSP Common Incident to Incident transform map under the PSP Common Transform Maps module. ServiceNow transform maps handle the format of data being shared into a ServiceNow instance. Making changes to the scripts for the specified transform map fields will ensure that data shared out of your Freshdesk instance will be mapped correctly to related fields in ServiceNow.

Prerequisites


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

(warning) You will also need to create custom ServiceNow outbound table map fields.

Procedure

To update the scripts for the required fields in the PSP Common Incident to Incident transform map, follow these steps:



Log into your ServiceNow instance and navigate to System Import Sets > Administration > Transform Maps or simply type and then select Transform Maps in the Filter Navigator on the upper left-hand side of the screen.

Search for and then click into the PSP Common Incident to Incident transform map.

Scroll down to the list of Field Maps. Then, search for an click into the u_description Source field.

Check the Use source script box. Then, delete the current script in the source script window and replace it with the following script:


answer = (function transformEntry(source) {
return source.u_description.replace(/<div>|<\/div>/g, "");
})(source);

(info) NOTE: Tickets created in Freshdesk with no value in the description field will automatically be assigned a description value of "None". To make this description blank when the record is shared to ServiceNow, change the script for u_description to the following:

answer = (function transformEntry(source) {
var text = source.u_description.toString().replace(/<div>|<\/div>/g, "");
if (text == “None”) {
return “”;
}
return text;
})(source);

Finally, click Update to save your changes.

Using Steps #3-4 as a guide, update the scripts for the fields as indicated below:

Source FieldScript to add
u_comments
answer = (function transformEntry(source) {
if (!source.u_comments.nil())
return "[code]" + source.u_comments + "[/code]";
return source.u_comments;
})(source);
u_priority
answer = (function transformEntry(source) {
if (source.u_priority == "1" || source.u_priority == "Low") {
target.impact = 3;
target.urgency = 2;
}
else if (source.u_priority == "2" || source.u_priority == "Medium") {
target.impact = 2;
target.urgency = 2;
 }
else if (source.u_priority == "3" || source.u_priority == "High") {
target.impact = 1;
target.urgency = 2;
}
else if (source.u_priority == "4" || source.u_priority == "Urgent") {
target.impact = 1;
target.urgency = 1;
}
target.impact = 3;
target.urgency = 3;
})(source);
u_state
answer = (function transformEntry(source) {
if (source.u_state == "2" || source.u_state == "Open") {
return "1";
}
else if (source.u_state == "3" || source.u_state == "Pending") {
return "2";
}
else if (source.u_state == "4" || source.u_state == "Resolved") {
return "6";
}
else if (source.u_state == "5" || source.u_state == "Closed") {
return "7";
}
return "2";
})(source);

(info) NOTEThe field mappings for priority and state are suggestions. The values assigned to answer in the script above can be changed to create custom mappings for these fields.

Click the Transform Scripts tab next to Field Maps. Then, click New. On the resulting Transform Script form, select onAfter from the When dropdown, and type 90 in the Order field. Finally, add the following script in the scripting window and click Submit to save your changes:

(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {

var pspS = new PerspectiumEncryption();
var pspR = new PerspectiumReplicator();
var ogr = new GlideRecord("psp_out_message");
ogr.addQuery("state", "deferred");
    var orQc = ogr.addQuery("u_extra", "CONTAINS", "number=" + source.u_number);
    orQc.addOrCondition("u_attributes", "CONTAINS", target.sys_id);
ogr.query();
while (ogr.next()) {
// update value with correlation id before we send out
var decodeData = pspS.decryptString(ogr.value);
decodeData = decodeData.replace("<correlation_id/>", "<correlation_id>" + target.correlation_id + "</correlation_id>");
decodeData = decodeData.replace("<correlation_display/>", "<correlation_display>" + target.correlation_display + "</correlation_display>");
        if (decodeData.indexOf("</attachments>") > -1) {
ogr.name = ogr.name.replace("update", "attach");
}

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

7. Click New to create another Transform Script. On the resulting Transform Script form, select onAfter from the When dropdown, and type 100 in the Order field. Finally, add the following script in the scripting window and click Submit to save your changes:

(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
if (!source.u_correlation_id.isNil()) {
return;
}

var pspR = new PerspectiumReplicator();
var ds = new GlideRecord("psp_replicate_conf");
ds.addQuery("u_target_queue.u_name", "psp.in.siam.client.freshdesk");
ds.addQuery("active", "true");
ds.addQuery("sync_direction", "share");
ds.query();
if (!ds.next()) {
return;
}

var gr = new GlideRecord("incident");
gr.addQuery("sys_id", target.sys_id);
gr.query();
if (gr.next()) {
pspR.shareRecord(gr, "incident", "update", ds.sys_id);
}
})(source, map, log, target);

Click into the existing onAfter Transform Script with an Order of 110. Within the code, search for msp_client_incident_sent. Replace this text with freshdesk_sent. Finally, click Update at the bottom right-hand corner of the screen to save your changes to this script.


Next steps


Add attachment.uploaded script action for Freshdsesk