how to write if condition for greater number in client script

Servicenow_12
Tera Contributor

Hi team,

I want to set assignment group using onload client script , if the number of users field value is greater than 200.

tried with below but its not entering into the loop.

var nou = g_form.getValue('number_of_users');
if (nou > 200) {
g_form.setValue("assignment_group", 'xyz');
}

 

Please help me with the right way of comparing the value with 200

 

1 ACCEPTED SOLUTION

Pavankumar_1
Mega Patron

Hi @Servicenow_12 ,

Try below script on onload client script and active is true

 

 

function onLoad() {
    var nou = g_form.getValue('number_of_users');
  var num = parseInt(nou );
    if (num> 200) {
        g_form.setValue("assignment_group", '02826bf03710200044e0bfc8bcbe5d3f'); //add group sysid here
    }
}

 

 

 If still not resolved try to add info message and check the value on number_of_users field.

or use display business rule and check and set it using onload client script

g_scratchpad.num=current.total_user; 
If it helps please click Accept as Solution/hit the Thumb Icon.
ServiceNow Community MVP 2024.
Thanks,
Pavankumar

View solution in original post

11 REPLIES 11

Mohith Devatte
Tera Sage
Tera Sage

Hello @Servicenow_12 ,

try this script .Use parseInt to convert it to integer and also set the sys_id of hte assignment group but not the name of the group 

Make sure you are using correct back end name of number of users field

var nou = g_form.getValue('number_of_users');
nou =parseInt(nou);
if (nou > 200) {
g_form.setValue("assignment_group", 'sys_id_of_group_record');
}

Hope this helps 

Mark my answer correct if this helps you 

Thanks

 

Hi @Mohith Devatte ,

got stuck with if condition while comparing the value.sysid has been given for AG