Outbound Rest API with a BR creating 2 Incidents

AkhilM
Tera Contributor

Hi,

I am trying create an Outbound Rest API connect between 2 ServiceNow instances. I set the BR to have dynamic field values to push to destination instance

HTTP Request:

{
"caller_id":"${caller}",
"priority":"${priority}",
"category":"${category}",
"short_description":"${shortdesc}"
}

However when I created an Incident in source instance 2 incidents get created in destination instance and also in system logs only one incident value gets updated. Can anyone please help on this?

Before Insert BR:

(function executeRule(current, previous /*null when async*/) {

var request = new sn_ws.RESTMessageV2('My Integration','my integration http');
request.setStringParameterNoEscape('caller',current.caller_id);
request.setStringParameterNoEscape('priority',current.priority);
request.setStringParameterNoEscape('category',current.category);
request.setStringParameterNoEscape('shortdesc',current.short_description);
request.execute();
var response = request.execute();
var requestBody = request.getRequestBody();
var responseBody = response.getBody();
var httpStatus=response.getStatusCode();
gs.log(responseBody);
responseJSON=responseBody.substring(10,responseBody.length-1);
parsedJSON=JSON.parse(responseJSON);
var targetIncidentNumber = parsedJSON['number'];
var targetsysid = parsedJSON['sys_id'];
var logString = 'Target Incident number - '+targetIncidentNumber+"\n Target Incident sysid-"+targetsysid;
gs.log(logString,'BR-API test');

})(current, previous);
4 REPLIES 4

Ankita Dutta
Tera Contributor

I am facing the same issue. Have you received any resolutions yet?

@Ankita Dutta On the target instance, try creating an onBefore insert business rule which checks if an incident with same details (caller, short description, description etc.) was created in last one minute if the condition evaluates to true then use current.setAbortAction(true); in the script.

AkhilM
Tera Contributor

Yes, As you can see in the attached code in my earlier post I had "request.execute();" which was causing another incident creation. I removed this line from the code and it works fine now

Worked for me.

Thanks a ton!!! 🙂