- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-01-2022 02:10 AM
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-01-2022 03:22 AM - edited 12-01-2022 06:58 AM
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;
ServiceNow Community MVP 2024.
Thanks,
Pavankumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-01-2022 03:04 AM
nou = Number(nou) or nou = parseInt(nou) can be used to convert the data type of number_of_users to Number from String.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-01-2022 03:33 AM
'number_of_users' actually returns the value in number , not in string form.
using Number(nou) , i am getting the o/p as NaN
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-01-2022 03:22 AM - edited 12-01-2022 06:58 AM
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;
ServiceNow Community MVP 2024.
Thanks,
Pavankumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-01-2022 03:42 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-01-2022 06:01 AM
Hi @Servicenow_12 ,
No that is not correct value. ParseInt parses the string and returns the whole number.
ServiceNow Community MVP 2024.
Thanks,
Pavankumar