Increase integer field by 1 when priority changes

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-23-2020 04:56 AM
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 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-23-2020 05:09 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-23-2020 05:23 AM
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-23-2020 06:14 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-23-2020 06:48 AM
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