Increment an integer field when a business rule runs.

kowens
Tera Contributor

I created an integer variable called "u_automation_launch_count" with the purpose of counting the number of times a business rule runs that launches an API for a particular incident. The business rule may run multiple times for the incident based on statuses. Below are the business rule specs, and everything works with the exception of being able to increment the  value of "u_automation_launch_count"

Code: 

current.u_automation_launch_count += 1;

try {
var r = new sn_ws.RESTMessageV2('Bamboo API', 'Bamboo POST');
r.setStringParameter("sys_id",current.sys_id);
r.setStringParameter("number",current.number);

var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
}
catch(ex) {
var message = ex.message;
}

 

find_real_file.png

Any assistance would be appreciated!

1 ACCEPTED SOLUTION

Yogi3
Kilo Guru

Hello Kowens,

 

i guess current.update(); is missing.

 

Try below code.

current.u_automation_launch_count += 1;

current.update();

try {
var r = new sn_ws.RESTMessageV2('Bamboo API', 'Bamboo POST');
r.setStringParameter("sys_id",current.sys_id);
r.setStringParameter("number",current.number);

var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
}
catch(ex) {
var message = ex.message;
}

 

Hope this helps!

View solution in original post

3 REPLIES 3

Yogi3
Kilo Guru

Hello Kowens,

 

i guess current.update(); is missing.

 

Try below code.

current.u_automation_launch_count += 1;

current.update();

try {
var r = new sn_ws.RESTMessageV2('Bamboo API', 'Bamboo POST');
r.setStringParameter("sys_id",current.sys_id);
r.setStringParameter("number",current.number);

var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
}
catch(ex) {
var message = ex.message;
}

 

Hope this helps!

best practise is to use, to avoid br calling itself.

current.setWorkflow(false);

current.update();

 

Other wise you can skip current.update() and run before BR instead of after.

kowens
Tera Contributor

Thank you Yogi! As I thought, it was one little thing...Much appreciated!!