When an incident is created in the source ServiceNow instance, a Flow Designer custom action triggers an outbound REST API call to create the same incident in a target instance. The target instance returns a JSON response, which is parsed and stored back in the source incident for confirmation and traceability.
Step 2: Configured HTTP Method
{
“sys_id”:”${id}”,
“caller_id” : “${cd}”,
“short_description” : “${sd}”
}
Step 3 :Created a Flow
Step 4 : Created a Custom Action
Step 5 : Mapped Flow Data to Action Inputs
Step 6 : Added Script Step in Custom Action
(function execute(inputs, outputs) {
try {
var r = new sn_ws.RESTMessageV2(‘Sample’, ‘Test’);
r.setStringParameterNoEscape(‘id’, inputs.id);
r.setStringParameterNoEscape(‘sd’, inputs.shortDescription);
r.setStringParameterNoEscape(‘cd’, inputs.callerId);
var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
gs.info(‘Response Body: ‘ + responseBody);
gs.info(‘HTTP Status: ‘ + httpStatus);
var parsedResponse = JSON.parse(responseBody);
var result = parsedResponse.result;
var targetIncidentNumber = result.number;
var shortDescription = result.short_description;
var priority = result.priority;
var category = result.category;
var subcategory = result.subcategory;
var state = result.state;
var callerSysId = result.caller_id.value;
var grIncident = new GlideRecord(‘incident’);
if (grIncident.get(inputs.id)) {
grIncident.description =
“Incident successfully created in Target Instance\n\n” +
“Target Incident Number: “ + targetIncidentNumber + “\n” +
“Caller Sys ID: “ + callerSysId + “\n” +
“Short Description: “ + shortDescription + “\n” +
“Priority: “ + priority + “\n” +
“Category: “ + category + “\n” +
“Subcategory: “ + subcategory + “\n” +
“State: “ + state;
grIncident.update();
}
} catch (ex) {
gs.error(‘Integration Error: ‘ + ex.message);
}
})(inputs, outputs);
Step 7: Executed Integration via Flow
Source Instance:
Before Integration Trigger:
Target Instance:
Source Instance:
After Integration Execution