Show requester contact details on change on catalog form

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-10-2023 10:32 PM
Hello All,
I have a requirement, on the catalog form there is a field requested for on change of this field I want to populate the user details like location, mobile no, business no, email etc., in another field, how to achieve this requirement.
Thanks in advance
Anand
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-10-2023 10:55 PM - edited 08-10-2023 10:57 PM
Hi Anand,
To do this you need to understand that you want to get server side data which is Requester details form User table and then populate it on Client side which is catalog item variables.
Now to do this you need a Script Include to fetch Server Side data and then pass it on to the Client Script which will populate the fields with client data.
Below is an example of Client callable Script Include:
var GetUserDetails = Class.create();
GetUserDetails.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getRequestor: function(){
var requestor= this.getParameter('requestor'); //sys_id of Requestor passed from Client script
var grUser= new GlideRecord('sys_user');
grUser.get(requestor);
var user= {};
user.Name= grUser.getValue('name');
user.Email= grUser.getValue('email');
//Add more fields for which you want value like above
return JSON.stringify(user);
},
Example of onChange Catalog Client script that will run on change of Requestor variable:
var ga = new GlideAjax('global.GetUserDetails');
ga.addParam('sysparm_name','getUser');
ga.addParam('user',newValue);
ga.getXMLAnswer(getResponse);
function getResponse(response){
var res = JSON.parse(response);
g_form.setValue('name',res.Name);
g_form.setValue('email',res.Email);
//Add more variable names and follow above pattern in function
}
If my answer helps then please mark it Helpful or Correct!
Thanks,
Utpal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-10-2023 11:06 PM
@Community Alums If your instance is in Utah version, then there is a OOB auto populate feature is available where you can auto populate values in fields based on other reference variable of your catalog item. In your case reference variable is "Requested for". Create location, mobile no , email variables and in "Auto populate" section of variable you can to do dot walk using "Requested for" variable. You don't have to write a single line of code here.
Refer below article where Auto populate functionality is properly exaplined
If I could help you with your Query then, please hit the Thumb Icon and mark as Correct !!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-10-2023 11:13 PM
Hi @Utpal Dutta , @SANDEEP28 ,
Thanks for your solution, but I want to show the details of the user in the below format.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-10-2023 11:25 PM
Details mentioned below Contact Details all these are fields in your catalog item right? If not then please explain what are you trying to achieve?