
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-17-2023 10:29 AM
Hi, I am working on a request catalog form with orchestration. I need to find a way to pull the user name field from the requested for field instead of the logged-in user. I am currently using a catalog client script with the code below to pull the user name but this gives me the logged in user name instead of the requested for. Any advice on how to get the user name for requested for?
function onLoad() {
var userID = g_user.userName;
g_form.setValue('user_name',userID);
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-31-2023 11:12 AM
I got the mistake that you are doing @juliochacon23 In client script code of 7th line change sysparam_sys to sysparm_sys and also change script include 5th line sysparam_sys to sysparm_sys .Then it will definitely work please check onces
If my solution helps you please mark my answer as accepted and helpful.
Thanks and Regards
Uday Kumar Valapudasu

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-31-2023 12:09 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-17-2023 10:54 AM
Hi @juliochacon23,
I would suggests to go with onchange catalog client scripts based on Requested for variable.
Scripts:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
getUserName();
return;
}
getUserName();
}
function getUserName() {
var user = g_form.getReference('requester_user', getDetails);
function getDetails(user) {
g_form.setValue("user_name", user.user_name);
}
}
Thanks,
Sagar Pagar

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-17-2023 03:07 PM
Thanks, I tried that and I did not get anything for user_name to match the requested for user name. The user name field is now blank. The field is called requested_for. I would like to call the user name of the user in this field and assign it to the field called user_name.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2023 10:17 AM - edited 03-20-2023 10:19 AM
You need to change that "Variable name" dropdown to be the 'requested_for' field so the script knows when to run and that's when the Requested For field changes
I would also advise adding the "Isolate Script" checkbox to your form....that field at times will need to be checked or unchecked depending on your use case with your script.
Please mark this response as correct and/or helpful if it assisted you with your question.
Steven
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-17-2023 11:20 PM
Hi @juliochacon23 How are you ?
You can achieve your requirement using Script Include and GlideAjax. I tried in my personal instance and working absolutely very good for your reference i am posting my code make change as per your field names @juliochacon23 .
Script Include:
var user_name = Class.create();
user_name.prototype = Object.extendsObject(AbstractAjaxProcessor, {
username:function()
{
var sys_id=this.getParameter('sysparam_sys');
var gr=new GlideRecord('sys_user');
gr.addQuery('sys_id',sys_id);
gr.query();
if(gr.next())
{
return gr.first_name+" "+gr.last_name;
}
},
type: 'user_name'
});
Onchange Client Script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;}
var usersys=g_form.getValue('requested_for');
var ga = new GlideAjax('user_name');
ga.addParam('sysparm_name', 'username');
ga.addParam('sysparam_sys', usersys);
ga.getXML(callBackFunction);
function callBackFunction(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
g_form.setValue('user_name', answer);}}
The Output of mine is here:
Please mark my response as helpful and accepted solution incase of any doubt please ask me @juliochacon23
Thanks and regards
Uday Kumar Valapudasu