Incrementing a Number

Invoke
Kilo Contributor

Hello,

I am wanting to increment a field by one in a UI action that I am using. I think I need to write this in my UI action something similar to:

current.u_number = getNextObjNumber();

However, I don't want the next object number as this will just give me the next incident number. When my button is pressed (UI Action) I just want the field to be updated with 1 and then next time with 2, the next time with 3 and so on....

Think its just a piece of javascript that i'm missing.

Can anyone help?

Thanks

5 REPLIES 5

brozi
ServiceNow Employee
ServiceNow Employee

If you do this as a client side UI Action you can do something like this

OnClick: plus1();



function plus1(){
var num = g_form.getValue('u_number');
num++;
g_form.setValue('u_number', num);
}


Invoke
Kilo Contributor

It's the 'communicate_workaround' UI Action that I am working on which isn't a client side script - any other ideas?


brozi
ServiceNow Employee
ServiceNow Employee

To increment a field just add this line then. Just change to your field.



current.u_number = current.u_number++;


brozi
ServiceNow Employee
ServiceNow Employee

I just looked at that UI Action, it depends on where you want that ++ to take place. If on the problem itself add the script of something similar to the beginning. If you want it to happen on the incident add after the while (incident.next()) {

Post back if you need help with that.