- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-11-2016 02:23 PM
I have a "selector" field on a form that references the sys_user table. It is a "List" type field so uses the little padlock icon to open the selector and select multiple values from the user table. I have 3 choices in another select box field. If "Yes - IS Global Only" is selected it displays the selector field and allows the requestor to select a user from the table. I need to auto-set a user in the selector if the option of "Yes - IS Global Only" is selected from the select box field. I used the following client script but it's not working:
function onChange() {
var SendNew = g_form.getValue('u_send_notification');//Select box field choices
if (SendNew == 'Yes - IS Global Only'){ //'Yes - IS Global Only' is one of 3 options
g_form.setValue('u_notify_user', 'IS Global');//Set the User in the selector box to IS Global
}
}
Any input would be appreciated. Thanks,
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-11-2016 08:52 PM
Hey Mike,
That should be fine. I am glad I was helpful to you. I am pasting the script and final code here.
Script :
function onChange() {
var SendNew = g_form.getValue('u_send_notification');
if (SendNew == "Yes IS Global" || SendNew == "Yes"){
g_form.setValue('u_notify_user','08c5f8b42bfbb1007e94559bf8da155b');//IS Global sys_id
}
if (SendNew == "No"){
g_form.clearValue('u_notify_user')
}
}
http://wiki.servicenow.com/index.php?title=GlideForm_(g_form)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-11-2016 07:09 PM
When the form loads, the Send New Notification (u_send_notification) select box field is set to -- None --. The condition would be if they select the option of "Yes - IS Global Only", then set the "Who to Notify" user to IS Global. See script with condition below
var SendNew = g_form.getValue('u_send_notification');//Send New Notification Select box field choices
if (SendNew == "Yes - IS Global Only"){
g_form.setValue('u_notify_user','08c5f8b42bfbb1007e94559bf8da155b');

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-11-2016 07:13 PM
Can you just print and see what value you are getting as output when you select "Yes-is global only" from the drop down. Based on that change the if loop
var SendNew = g_form.getValue('u_send_notification');
alert(SendNew);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-11-2016 07:42 PM
Looks like that did it. The alert displayed the select box value and I was using the label display name in the condition. The script belowworks, setting the variable to the value of the select box option, NOT the label name.
Just one more question if you don't mind....Do you know how I would clear IS Global from the "Who to Notify" field if they select the No option (see screen shot below)
function onChange() {
var SendNew = g_form.getValue('u_send_notification');
alert(SendNew);
if (SendNew == "Yes IS Global"){
//alert('in loop');
g_form.setValue('u_notify_user','08c5f8b42bfbb1007e94559bf8da155b');//Replace IS Global with the sys_id of the record
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-11-2016 07:54 PM
Disregard Pradeep, I got it working. Needed to account for the other Yes option and I used the clearValue for the No option. The below script works for all 3 options now. Thanks much for your time on this...much appreciated. If you want to copy the script below in a reply, I can mark it as the correct answer so you receive the credit deserved. Thanks again.
function onChange() {
var SendNew = g_form.getValue('u_send_notification');
if (SendNew == "Yes IS Global" || SendNew == "Yes"){
g_form.setValue('u_notify_user','08c5f8b42bfbb1007e94559bf8da155b');//IS Global sys_id
}
if (SendNew == "No"){
g_form.clearValue('u_notify_user')
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-11-2016 08:52 PM
Hey Mike,
That should be fine. I am glad I was helpful to you. I am pasting the script and final code here.
Script :
function onChange() {
var SendNew = g_form.getValue('u_send_notification');
if (SendNew == "Yes IS Global" || SendNew == "Yes"){
g_form.setValue('u_notify_user','08c5f8b42bfbb1007e94559bf8da155b');//IS Global sys_id
}
if (SendNew == "No"){
g_form.clearValue('u_notify_user')
}
}
http://wiki.servicenow.com/index.php?title=GlideForm_(g_form)