- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2017 07:40 AM
Hello all,
I'm trying to create a UI Policy script that when certain categories are picked it will run the script to get a specific user and sets them into a field.
Here is the script I have so far:
function onCondition() {
var getUser = new GlideRecord('sys_user');
getUser.addQuery('user_name', Jdoe);
getUser.query();
while (getUser.next()) {
g_form.setValue('approvalRequestedApproval', getUser);
}
}
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2017 08:09 AM
Hi Jacob,
Looking at your script, you have hard coded the assignee to "Jdoe" // getUser.addQuery('user_name', Jdoe);
1. If you want to assign those the task for that particular person, you can hard code the "sys_id" of "Jdoe" to approvalRequestedApproval instead of Querying user table using OnChange Client script.
2. If you want to to be it Dynamic based on the requirement you can use http://wiki.servicenow.com/index.php?title=GlideAjax#gsc.tab=0
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2017 08:00 AM
Hello,
I don't really have a preference between using a UI Policy or a Client Script but the UI Policy seemed easier because I could define the conditions simply.
I have a select box field with different categories in the drop down. When I select certain categories I want the user reference field to populate with 1 specific user. Otherwise the user field is open to select a user.
I changed the JDoe to 'JDoe' but the field returns blank. I've also never used a GlideAjax, would it be as simple as just replacing the GlideRecord?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2017 08:06 AM
Hello Jacob,
Thanks for the update. If the user per condition is always static then you need not do GlideRecord or GlideAjax calls and instead can be set via g_form.setValue
i.e g_form.setValue('approvalRequestedApproval', 'sys_id of the user'); //Also make sure field column name is correct i.e approvalRequestedApproval. If this is a custom field it should have prefix(u_) i.e u_approvalRequestedApproval

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2017 08:09 AM
Hi Jacob,
Looking at your script, you have hard coded the assignee to "Jdoe" // getUser.addQuery('user_name', Jdoe);
1. If you want to assign those the task for that particular person, you can hard code the "sys_id" of "Jdoe" to approvalRequestedApproval instead of Querying user table using OnChange Client script.
2. If you want to to be it Dynamic based on the requirement you can use http://wiki.servicenow.com/index.php?title=GlideAjax#gsc.tab=0
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2017 11:33 AM
The ServiceNow Wiki content is no longer supported. Updated information about this topic is located here: AJAX
Visit http://docs.servicenow.com for the latest product documentation