The CreatorCon Call for Content is officially open! Get started here.

Business rule is running twice with async and update?

Santhosh15
Tera Guru

Hello all,

 

When I am using current.update() in my code, the business rule is running twice for assigning ticket to some other team.

Please help on this issue.

 

Code Below:

=================================================

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

// Add your code here
var httpStatus = current.u_http_status_code;

if (httpStatus == 201) {
gs.log("inside 201 block" + httpStatus);
var seconds = 90;
var second = parseInt(seconds, 10) * 1000;
var start = parseInt(new Date().getTime()) + second;
while (start > parseInt(new Date().getTime())) {
// do nothing
}
gs.log("outside the waitblock while loop response w");
if (current.sys_updated_by != "svc.awx") {
current.assignment_group = "72fb418d13c863004d8e5ce12244b008"; //Unix
current.update();
}

} else {
current.assignment_group = "e6fb018d13c863004d8e5ce12244b0dc"; //ServiceNow Team
current.update();
}

})(current, previous);

16 REPLIES 16

Hello @Ankur Bawiskar,

 

I am using async business rule because the process should be run on backend and this code is excuting to third party integartion to ServiceNow.

 

If i use Before instead of async then process is excuting at front end once the process is completed the ticket is assigning to specific assignment group.

 

Thank you

@Santhosh15 

in your script there is no REST Message or SOAP Message line which says you are integrating.

Is there any other BR for that?

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

Yes, I am using another business rule for Rest Message

@Santhosh15 

why not combine both the logic in single async BR?

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

I have combine to one BR now

 

Below is the code

 

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

try {

var r = new sn_ws.RESTMessageV2('Rest using Basic Auth', 'Job Template');
r.setStringParameterNoEscape('number', current.number);
r.setStringParameterNoEscape('linux_host', current.res);
r.setStringParameterNoEscape('linux_host_name', current.res_1);
r.setStringParameterNoEscape('sys_id', current.sys_id);

var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();


current.state = '2';
current.u_http_status_code = httpStatus;
// current.update();
gs.addInfoMessage(httpStatus);
gs.addInfoMessage(responseBody);

if (httpStatus == 201) {
gs.log("inside 201 block" + httpStatus);
var seconds = 90;
var second = parseInt(seconds, 10) * 1000;
var start = parseInt(new Date().getTime()) + second;
while (start > parseInt(new Date().getTime())) {
// do nothing
}
gs.log("outside the waitblock while loop response w");


if (!(current.work_notes.getJournalEntry(-1))) {
gs.log("inside if block");
current.assignment_group = "72fb418d13c863004d8e5ce12244b007"; 
}

} else {
current.assignment_group = "72fb418d13c863004d8e5ce12244b007";
gs.log("outside else block");
}

var jsonObject = JSON.parse(responseBody);

} catch (ex) {
var message = ex.message;
gs.addInfoMessage("Catch" + JSON.stringify(message));
}
})(current, previous);