How to populate users details after selecting one variable of record producer?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2023 03:16 AM - edited 06-20-2023 03:18 AM
Hi All,
I have a requirement where in a record producer I need to populate users' details like email, department, and designation when they'll select one field eg. name.
I've used data lookup definitions which is working fine but since we're fetching data from a large number of records, it's taking too much time to load.
I want to know if there are any other ways to do it by client script or something.
The first field that the user will select is of type 'string'. Is that any consequences of this? Or is it required that the field should be of 'reference' type only?
Please let me know if anyone got something.
Thanks,
Amol

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2023 03:36 AM
Hello @Amol Pawar
Any reason to have name field as string type instead of reference? Having it reference would make it to validate the names in user table, and also you can bring user's details from selected user record.
To auto-populate user details on variables, if you are in Utah release refer below article to configure it without any code.
If not on Utah, refer below thread to use client script/Glide ajax to bring the data from server and autopopulate.
Thank you,
Ali
Thank you,
Ali
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2023 04:50 AM
Hi @Amol Pawar ,
Hope you are doing great.
Instead of relying solely on data lookup definitions, we can leverage AJAX techniques to perform asynchronous calls to the server and retrieve the required user information in real-time.
sample approach using client script to achieve this functionality:
function populateUserDetails() {
var name = g_form.getValue('name');
var ga = new GlideAjax('FetchUserDetailsAjax');
ga.addParam('sysparm_name', 'getUserDetails');
ga.addParam('sysparm_user_name', name); // Pass the selected name as a parameter
ga.getXML(function(response) {
var xmlDoc = response.responseXML;
var userNode = xmlDoc.getElementsByTagName('user')[0]; // Assuming the server-side script returns XML
var email = userNode.getAttribute('email');
var department = userNode.getAttribute('department');
var designation = userNode.getAttribute('designation');
// Populate the corresponding fields on the form
g_form.setValue('email', email);
g_form.setValue('department', department);
g_form.setValue('designation', designation);
});
}
Regards,
Riya Verma