Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

To fetch Userid of the Requested for user on the catalog form

Rahul84
Tera Contributor

Hi All,
I want to fetch the userid of the "Requested for" user from the catalog form.

example - I have a field Requested for on the catalog form.
I want to fetch the user id of this Requested for user on the Onchange catalog client script

for example - Requested for user is - Rahul Sharma , so i want the user of the user - Rahrma (combination of first and last name).

Pls help with solution.

3 REPLIES 3

Brad Bowman
Kilo Patron
Kilo Patron

If you ultimately only need the value, like user id to populate in another variable, try the code-less approach:

https://www.servicenow.com/community/developer-articles/catalog-data-lookup-definition-on-any-table-...

If you actually need the value (Rahrma) to further use in the same script, then you'll want to use a getReference with callback to lookup the value on the user table field based on the selected user.

https://docs.servicenow.com/bundle/tokyo-application-development/page/app-store/dev_portal/API_refer... 

@Brad Bowman   : can you please help me with the logic , I need to fetch the value of the (Requested for) user id and need to store it in the input variable. Instead of sys_id , I want user id. It will be great of you can help with the code/script.

var userID = g_form.requested_for.sys_id;
var inputs = {};
inputs['user_sys_id'] = userID; // String

function onChange(control, oldValue, newValue, isLoading) {
    g_form.getReference('requested_for', getUser);
}
 
function getUser(caller) { 
    var userID = caller.user_name
}