Rest call occurring twice during single update.

Fathima6
Tera Expert

Hi all!

I am updating single record in a single time but the api is hitting twice.

Description : 

I created import set row table u_abc for targeting incident table using "number" and "work_notes" field. The table u_xyz have u_id and u_work_notes. Whenever I update those two field, Before business rule will run and call rest message to insert record in  u_abc and finally update the incident record via transform mapping. 

Issue : 

Now the issue is, execution happening twice during every single update. Two times inserting in import table u_abc, at the same time two times updating incident table also

find_real_file.png

This is my BR:

Table : u_xyz
When : Before Update
Order : 13,500

Script : 

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

// Add your code here
gs.log("rest details"+current.u_id + current.u_work_notes);
var request = new sn_ws.RESTMessageV2("ServiceNow sample", "update comments");
request.setStringParameterNoEscape("number", current.u_id);
request.setStringParameterNoEscape("notes", current.u_work_notes);
request.execute();
var response = request.execute();
var requestBody = request.getRequestBody();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
gs.log("response_incident" + httpStatus + responseBody );

})(current, previous);

This is my Rest message : 

Using import API 

{"u_number":"${number}","u_work_notes":"${notes}"}

Can anyone help?

Thanks in advance!

13 REPLIES 13

No Its not working. If I changed to after or async , then records getting inserted in u_abc import set table but its not updating in incident table.

fyr this is my endpoint : https://xyz.service-now.com/api/now/import/u_abc

Hi,

the ideal way to handle this is via After BR.

Can you explain below questions?

1) You are using BR on incident table in instance A

2) Which instance endpoint is being consumed in the Rest Message? is it the same instance or another instance

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

same instance

Hi,

so possibly the BR is triggering 2 times

please add this condition in the BR and check once

gs.getSession().isInteractive()

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

even not using business rule, and trying via widget also calling twice