User Tools

Site Tools


servicenow_salesforce_casecomment

ServiceNow to Salesforce Comment Configuration

Before continuing with this configuration, be sure to follow the steps from the ServiceNow and Salesforce Configuration page.

Table Maps

Sending to the CaseComment table is also supported. Unlike Incident to Case, the target for this table is CaseComment and the source table is “Journal Entry [sys_journal_field]”. Below are attached images for examples:

Below are the source script for required fields above

attributes:

answer = {"type":"CaseComment"};

isPublished:

if (current.element.contains("comment"))
	answer = "true";

ParentId:

var gr = new GlideRecord('incident');
gr.addQuery("sys_id", current.element_id.toString());
gr.query();
if (gr.next())
	answer = gr.correlation_id.toString();

@RecordId:

var gr = new GlideRecord('incident');
gr.get(current.element_id.toString());
answer = gr.sys_id.toString();

CommentBody:

var pspUtil = new PerspectiumUtil();
var gr = new GlideRecord('incident');
gr.addQuery("sys_id", current.element_id.toString());
gr.query();
gr.next();

var elementId = gr.sys_id;
var tgr = new GlideRecord("sys_journal_field");
tgr.addQuery("element_id", elementId);
tgr.orderByDesc("sys_created_on");
tgr.query();
if (tgr.next())
	pspUtil.addTag(tgr, "msp_client_incident_sent");

answer = current.value;

Transform Maps

Receiving into the CaseComment table is also supported. The source for this table is CaseComment and the target table is “Journal Entry [sys_journal_field]”. Below are attached images for examples:

Below are the source script for required fields above

element_id:

var gr = new GlideRecord("incident");
gr.addQuery("correlation_id", source.u_parentid);
gr.query();
gr.next();
return gr.sys_id; // return the value to be put into the target field

element:

return "comments"; // return the value to be put into the target field

name:

return "incident"; // return the value to be put into the target field

Once the field mappings are created, a onBefore transform script is necessary for insertion. Refer to the image and script below for an example.

var gr = new GlideRecord("incident");
gr.addQuery("correlation_id",source.u_parentid);
gr.query();
gr.next();

var elementId = gr.sys_id;
var tgr = new GlideRecord("sys_journal_field");
tgr.addQuery("element_id", elementId);
tgr.addQuery("value", source.u_commentbody);
tgr.orderByDesc("sys_created_on");
tgr.query();
if (tgr.next() && pspUtil.recordHasTag(tgr, "msp_client_incident_sent")) {
	ignore = true;
	return;
}

pspUtil.addTag(tgr, "msp_client_incident_sent");

gr.comments.setJournalEntry(source.u_commentbody);
gr.setForceUpdate(true);
gr.update();

Dynamic Share

After setting the table maps, dynamic share may now properly be able to reference them. The following images are an example for configuring the ServiceNow Journal Entry (sys_journal_field) table to share out to Salesforce CaseComment object. Here is also a guide for how to set up a dynamic share.

Keep in mind that from comments made in the Incident table are then created in the Journal Entry table. From there, the comments are then sent to CaseComment onto Salesforce.

Be sure to include the “before share script” provided below. This will defer comments that do not have a correlation id and will put it on stand by.

var gr = new GlideRecord("incident");
gr.addQuery("sys_id", current.element_id);
gr.query();
gr.next();

if ((psp_action == 'update' || psp_action == 'insert') && gr.correlation_id == ''){
	psp_action = 'deferred';
}
servicenow_salesforce_casecomment.txt · Last modified: 2019/12/04 14:43 by vinhn