Increase integer field by 1 when priority changes

Teresa Ruiz
Tera Contributor

Hi guys,

I made an integer field in my incident form and default value 0 and I need to increment this field by 1 everytime the priority changes.

I tried this with business rule but i cant seem to find the right way.

 

g_form.setValue('u_priority_counter', g_form.getValue('u_priority_counter') + 1);

 

Thanks to any help 🙂

6 REPLIES 6

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Teresa,

you should do this using before update business rule:

BR Condition: priority changes

Script:

current.u_priority_counter = parseInt(current.u_priority_counter) + 1;

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

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

Aniket Sawant
Mega Expert

Hi,

You could do this by using client script  as follows.

Table - incident

type- onchange

Fieldname-Priority

Script:

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var cnt =g_form.getValue('u_counter_1');
cnt++;
g_form.setValue('u_counter_1', cnt);
//Type appropriate comment here, and begin script below

}

 

or you could replace code by following

var cnt =g_form.getValue('u_counter_1');
cnt++;
g_form.setValue('u_counter_1', cnt);

 

Please mark correct or helpful based on impact.

Regards,

Aniket Sawant.

Ashutosh Munot1
Kilo Patron
Kilo Patron

Hi,

Create a Before update business rule as below:

1) Condition:

Priority changes and priority is not empty.

2) Advance Script:

var num = 1;

current.urfieldname= parseInt(current.u_alpha) + parseInt(num);

 

Thanks,
Ashutosh Munot

Hemant Goldar
Mega Sage
Mega Sage

Hi,

 

Set by default value=0

Create a (Before) Business Rule -->Business rule should run on Update.

Filter Condition: Priority changes

 

 Script:

var count=parseInt(current.fieldname);

current.fieldname=count+1;

 

Thanks and Regards,

Hemant