- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-23-2023 04:30 AM
Hello everyone,
I would like to automatically populate certain data for the Record Producer. These include gender, phone number, and company/car policy. Do you know how I can accomplish this?
Thank you for your assistance!
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-24-2023 07:43 PM
Try this updated script for phone number.
var GetUserInfo = Class.create();
GetUserInfo.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
getUserDetails: function() {
var userName = this.getParameter("sysparm_user_id");
var grUser = new GlideRecord('sys_user');
grUser.get("sys_id", userName);
// Build the payload. You can return additional data if needed.
var result = {
"first_name": grUser.getDisplayValue('first_name'),
"last_name": grUser.getDisplayValue('last_name'),
"gender": grUser.getDisplayValue('gender'),//similarly add other fields
"phone_number": grUser.getDisplayValue('phone'),//similarly add other fields
"mobile_number": grUser.getDisplayValue('mobile_phone')//similarly add other fields
};
return JSON.stringify(result);
},
type: 'GetUserInfo'
});

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-23-2023 06:24 AM - edited ‎10-23-2023 06:25 AM
@Alik_92 You need to use the GlideAjax in a client script to fetch the user details. Here is the example script you can use as a part of an onLoad client script on a record producer.
function onLoad(){
var ga = new GlideAjax('HelloWorld'); // HelloWorld is the script include class
ga.addParam('sysparm_name','getUserDetails'); // helloWorld is the script include method
ga.addParam('sysparm_user_name',g_user.userID); // Set parameter sysparm_user_name
ga.getXML(getUserDetailsParse);
function getUserDetailsParse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer); //set the user details here
}
}
Here is your script include script.
var GetUserInfo = Class.create();
GetUserInfo.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
getUserDetails: function() {
var userName = this.getParameter("sysparm_user_id");
var grUser = new GlideRecord('sys_user');
grUser.get("sys_id", userName);
// Build the payload. You can return additional data if needed.
var result = {
"first_name": grUser.getDisplayValue('first_name'),
"last_name": grUser.getDisplayValue('last_name'),
"gender": grUser.getDisplayValue('gender')//similarly add other fields
};
return JSON.stringify(result);
},
type: 'GetUserInfo'
});
Hope this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-24-2023 12:21 AM
Hi, I want the phone number to be displayed directly. How can I achieve that using GlideAjax? I've prepared a String for it on ServiceNow.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-24-2023 07:43 PM
Try this updated script for phone number.
var GetUserInfo = Class.create();
GetUserInfo.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
getUserDetails: function() {
var userName = this.getParameter("sysparm_user_id");
var grUser = new GlideRecord('sys_user');
grUser.get("sys_id", userName);
// Build the payload. You can return additional data if needed.
var result = {
"first_name": grUser.getDisplayValue('first_name'),
"last_name": grUser.getDisplayValue('last_name'),
"gender": grUser.getDisplayValue('gender'),//similarly add other fields
"phone_number": grUser.getDisplayValue('phone'),//similarly add other fields
"mobile_number": grUser.getDisplayValue('mobile_phone')//similarly add other fields
};
return JSON.stringify(result);
},
type: 'GetUserInfo'
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-23-2023 06:35 AM
if you want those variables to be auto-populated based on a reference variable which refers to sys_user then no scripting is required.
if you are on utah version then check this link
Auto-Populate Reference data in Service Catalog
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader