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

Sajilal
Mega Sage

Is only update checked in business rule or both? Just have insert/update checked and see if it resolves?

find_real_file.png

Please Mark as Correct if this solves your issue and also mark ???? Helpful if it helps resolve your problem.

Thanks,
Saji

only update

I see a comment in your Description "and finally update the incident record via transform mapping. " maybe can you not do this and see if system updates the record by backend only?

Thanks,

Saji

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

it is recommended to call the Rest Message in After or Async business rule and not in the before business rule

Please make the BR as After and test once

Regards
Ankur

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