Set state value from a client script

saidarao
Tera Contributor

I got a script that is setting the 'assignet_to' to null when the assignment group changes. I want the same script to set the state to a value 1 (Unassigned).

It sort of does it, but initially displays 1, instead of Unassigned. How do I get it to display the label rather than the value just after the 'assignment_group' value changes?

The script I have is:
function onChange(control, oldValue, newValue) {
if (oldValue == newValue) {
return;
}
else {
g_form.setValue('assigned_to', '');
g_form.setValue('state', '1');
}
}

1 ACCEPTED SOLUTION

HugoFirst
Kilo Sage

See this doc: https://docs.servicenow.com/bundle/geneva-servicenow-platform/page/app-store/good_practices/client_script/concept/c_UseDisplayValParam.html

 

The second example in this page shows how to set the display value in the assignment statement.

An example could be:  g_form.setValue('state', 1, "Unassigned");

 

 

 

View solution in original post

4 REPLIES 4

Anurag Tripathi
Mega Patron
Mega Patron

try using g_form.setValue('state', 1); instead of g_form.setValue('state', '1');  

 

-Anurag

still, I am getting the same result

Then it is just the load time of the form, there is nothing much you can change in this script but check if there is anything else that is taking more time and hence resulting in longer form load time.

-Anurag

HugoFirst
Kilo Sage

See this doc: https://docs.servicenow.com/bundle/geneva-servicenow-platform/page/app-store/good_practices/client_script/concept/c_UseDisplayValParam.html

 

The second example in this page shows how to set the display value in the assignment statement.

An example could be:  g_form.setValue('state', 1, "Unassigned");