Rest call occurring twice during single update.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-28-2020 02:38 AM
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
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!
- Labels:
-
Integrations
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-28-2020 04:27 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-28-2020 04:53 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-28-2020 05:23 AM
same instance
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-28-2020 05:29 AM
Hi,
so possibly the BR is triggering 2 times
please add this condition in the BR and check once
gs.getSession().isInteractive()
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-28-2020 05:57 AM
even not using business rule, and trying via widget also calling twice