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 06:01 AM
Hi,
you have BR configured for triggering the REST Message so please add the condition in the BR
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 06:05 AM
still getting twice
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-28-2020 06:10 AM
Hi,
few things to check
1) why are you consuming same instance endpoint in the same 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 06:26 AM
Actually two api calls generating to the third party end user side so I can't able to check in their end so calling my instance instead, therefor found two calls generating.
now wondering that , I called the same endpoint with the same parameters via postman, its hitting once . Again checking the same via widget by calling rest message its failing. Now I deactivated all BR in the particular table and trying via widget using the below code during button click
var request = new sn_ws.RESTMessageV2("ServiceNow sample", "update_comments");
request.setStringParameterNoEscape("number", orde.u_id);
request.setStringParameterNoEscape("notes", comments);
request.execute();
gs.log("rest details"+orde.u_id + comments);
var response = request.execute();
var requestBody = request.getRequestBody();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
gs.log("response_incident" + httpStatus + responseBody );