The ServiceNow to Salesforce integration allows for replication of data between ServiceNow and Salesforce.
Below are step by step configurations of both systems, using an integration of ServiceNow incidents and Salesforce cases as an example.
Click here for a guide on how to install update sets on ServiceNow. If you have not received the respective update sets mentioned, please contact our support so they may assist you. Below are the necessary update sets for integrating ServiceNow to Salesforce.
Update Sets |
---|
Perspectium for ServiceNow Core |
Perspectium Salesforce |
In order to properly share out records from ServiceNow tables to Salesforce objects, outbound table maps will need to be created that shares out JSON as can be read by Salesforce.
Because we're going from incident on ServiceNow to case on Salesforce, the target table name will be set to “Case” and data will be passed in as a JSON.
You may also send Incident comments from ServiceNow to the Salesforce CaseComment table or even attachments in general. Refer to the pages below in order to do so.
ServiceNow Salesforce Attachments
Below are mappings for values from ServiceNow to Salesforce. “snn_c” is an example of a custom field. The custom field is a custom object that will be created on Salesforce in which the number will be passed into. In this case, the custom object is snn_c, which may be named differently by the user. The other fields are required.
Below are the source script for required fields above:
@ExternalIdField:
answer="Salesforce_object_here";
attributes:
answer= {"type":"Case"};
correlation_id:
if(current.correlation_id != null && current.correlation_id != "") answer = current.correlation_id.toString();
siam_integration_type:
answer="Salesforce";
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 incident table to share out to Salesforce case object. Here is also a guide for how to set up a dynamic share.
Before share script:
if (psp_action == 'update' && current.correlation_id == ''){ psp_action = 'deferred'; }
By default, the import set table, u_sfdc_case, is provided by the update set to read in records passed from Salesforce into ServiceNow.
The u_sfdc_case transform map creates the integration between Salesforce case to ServiceNow incident table. The following fields below are required for the integrations to be made. The snn__c is to be replaced by the custom object created on Salesforce by the user.
Set coalesce in the custom object to true. This will create a record if it is nonexistent.
The following transform scripts must be saved in the transform maps, as mentioned previously, and will take affect once messages from Salesforce are received in ServiceNow. They will share out the incident numbers, and deferred records and attachments once the record has received its' correlation ID.
onAfter script to share out deferred records:
var ogr = new GlideRecord("psp_out_message"); var pspS = new PerspectiumEncryption(); ogr.addQuery("state", "deferred"); //replace source.u_snn_c with correct variable ogr.addQuery("u_attributes", 'CONTAINS', "ExternalIdValue=" + source.u_correlation_display_c); ogr.queryNoDomain(); var jsonParser = new JSONParser(); while (ogr.next()) { var cipher; if (ogr.u_attributes.indexOf("cipher=2") > -1) cipher = "2"; else if (ogr.u_attributes.indexOf("cipher=4") > -1) cipher = "4"; else cipher = "3"; var names = String(ogr.name).split("."); if (names.length != 2 || names[1] != "update") { continue; } var decoded = pspS.decryptStringWithCipher(String(ogr.value), cipher); var newValue = jsonParser.parse(decoded.toString()); var att = ogr.u_attributes.toString(); if (att.indexOf(target.sys_id) < 0) continue; if (names[0] == 'Attachment' || names[0] == 'CaseComment') { ogr.name = names[0] + '.insert'; newValue.ParentId = source.u_id.toString(); } else if (names[0] == 'Case') newValue.Id = source.u_id.toString(); else continue; var str = JSON.stringify(newValue); ogr.value = pspS.encryptStringWithCipher(str, cipher); ogr.u_extra = ""; ogr.state = "ready"; ogr.update(); }
onAfter script to share out ServiceNow incident numbers to Salesforce:
(function runTransformScript(source, map, log, target /*undefined onStart*/ ) { // replace source.u_snn_c with your custom object if(source.u_snn_c != ""){ return; } var qgr = new GlideRecord("u_psp_queues"); var queue = ""; //enter queue in replace here qgr.addQuery("u_name", "REPLACE_HERE"); qgr.query(); if (!qgr.next()){ return; } queue = qgr.sys_id; var qc = new GlideRecord("psp_replicate_conf"); qc.addQuery("table_name", "incident"); qc.addQuery("u_target_queue", qgr.sys_id); qc.query(); if (!qc.next()){ return; } var gr = new GlideRecord("incident"); gr.addQuery("sys_id", target.sys_id); gr.query(); if (gr.next()){ var pspR = new PerspectiumReplicator(); pspR.shareRecord(gr, "incident", "update", qc.sys_id); } })(source, map, log, target);
For this script, make sure to enter your queue and custom object into the designated areas.
The script action is provided by default. It will fire once attachments are made to an incident record.