- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2024 02:26 AM
Hey there,
i've created a new catalog item to make a change department request.
My catalog item has 3 variables (type: reference): user_to_move, approver_user and move_in_department.
On approver_user variable, i've setted "Auto-populate" to question "User to move" and my dot walk path is 'Manager'.
Now i want this interaction:
If i choose an user (user_to_move) without Manager (manager field is empty, in user form), the Approver user field in form mustn't be read-only and I can choose a value selecting an user.
Insted, if the user choosen (user_to_move) has a manager, the field 'Approver user' must auto-compile with the name of the user's manager.
I've created a Catalog Client Script, but nothing change.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == 'user_to_move') {
onChangeUserToMove();
}
function onChangeUserToMove() {
var userToMove = g_form.getValue('user_to_move');
var manager = getManager(userToMove);
var approverField = g_form.getControl('approver_user');
if (manager !== null) {
g_form.setValue('approver_user', manager);
g_form.setReadOnly('approver_user', true);
} else {
g_form.setReadOnly('approver_user', false);
approverField.removeAttribute('disabled');
}
function getManager(userID) {
var userRecord = new GlideRecord('sys_user');
userRecord.addQuery('sys_id', userID);
userRecord.query();
if (userRecord.next()) {
return userRecord.getValue('manager');
}
return null;
}
}
}
Thank you.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2024 03:23 AM
Hi,
Try below script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
if(newValue!=''){
onChangeUserToMove();
}
function onChangeUserToMove() {
var userToMove = g_form.getReference('user_to_move',getManager);
function getManager(userToMove) {
var manager = userToMove.manager;
if (manager =='' || manager == undefined) {
g_form.setReadOnly('approver_user', false);
} else {
g_form.setValue('approver_user', manager);
g_form.setReadOnly('approver_user', true);
}
}
}
}
Thanks
Anil Lande

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2024 02:31 AM
Hi,
Not sure why you are using GlideRecord and getControl() API's
You can use g_form.setReadonly('field_name', false); to make make field editable (remove disable)
use g_form.getReference to get manager of user.
https://servicenowguru.com/scripting/client-scripts-scripting/gform-getreference-callback/
Thanks
Anil Lande

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2024 02:38 AM
Please try below script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
if(newValue!=''){
onChangeUserToMove();
}
function onChangeUserToMove() {
var userToMove = g_form.getReference('user_to_move',getManager);
var manager = getManager(userToMove);
function getManager(userToMove) {
var manager = userToMove.manager;
if (manager !== null) {
g_form.setValue('approver_user', manager);
g_form.setReadOnly('approver_user', true);
} else {
g_form.setReadOnly('approver_user', false);
}
}
}
}
if you are testing it on Service Portal then change UI Type on your client script configuration. You have selected 'Desktop' in UI Type on your client script.
Thanks
Anil Lande
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2024 03:04 AM - edited 01-04-2024 03:05 AM
i encountered this error on the employee center page when selecting a user on the form.
In the 'approver_user' variable, I removed the read-only check and the 'auto-populate' function.
When I select a user in the form, the 'approver_user' field becomes read-only. If the selected user has a manager, it displays properly. However, if the user doesn't have a manager, the 'approver_user' field remains read-only, and I can't change it.
However, i really appreciate your help. Thank you very much.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2024 03:13 AM
Hi,
Can you please share your latest script?
Thanks
Anil Lande