SetValue using sys_id
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-19-2016 01:19 PM
My client needs the assigned to field to be mandatory for certain users. The issue I am having is the client also needs to assignment group to not show in this same situation. We have the assigned to field as a reference to the assignment group. I tried using the following script in a client script and it is not functioning as I thought it would. The assignment group is showing up false and the assigned to field no longer as the correct options under it.
Here is my script:
function onLoad() {
if (g_user.hasRole('test_user) && !g_user.hasRole('admin_user)){
g_form.setMandatory('assignment_group', false);
g_form.setDisplay('assignment_group', false);
g_form.setValue('assignment_group', '(sys id here', 'display value here');
g_form.setMandatory('assigned_to);
}else{
g_form.setDisplay('assignment_group', true);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-20-2016 04:59 AM
Thanks all for your help. It was as simple as for some reason the sys_id wasn't mapping to the righ tcompany found the right sys id and works great. Thanks for all your help!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-21-2016 06:26 PM
Thanks Kimberly for the update.
Can you please mark the correct response and close the loop if your query is resolved now.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-19-2016 01:31 PM
Hi Kimberly,
1. Error in line g_form.setMandatory('assigned_to); should g_form.setMandatory('assigned_to', true);
Client Scripts - ServiceNow Wiki