- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-08-2023 09:57 PM
in catalog form i need to autopopulate field like location, phone no etc. i written script include and client script.
but it's not fetching value.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-08-2023 10:13 PM - edited 08-08-2023 10:17 PM
Hello @Gillerla Rajesh ,
try below code
Client Script :
// Client script for onChange on change of requestor
function onChangeUser() {
var requester = g_form.getControl('requester'); // Replace 'requester' with the actual field name
// Create a GlideAjax instance and specify the script include name
var ga = new GlideAjax('CustomUserUtils'); // Replace 'CustomUserUtils' with your actual script include name
ga.addParam('sysparm_name', 'getUserInfo'); // script include function name
ga.addParam('sysparm_user', requester);
ga.getXML(getResponse);
function getResponse(response) {
var answer = response.responseXML.documentElement.getAttribute('answer');
if (answer) {
var userInfo = JSON.parse(answer);
g_form.setValue('location_field', userInfo.location);
g_form.setValue('phone_number_field', userInfo.phone_number);
}
}
Script include : make sure it should be client callable
getUserInfo: function() {
var userId = this.getParameter('sysparm_user');
var userInfo = {};
var userGR = new GlideRecord('sys_user');
if (userGR.get(userId)) {
userInfo.location = userGR.location.getDisplayValue();
userInfo.phone_number = userGR.phone.getDisplayValue();
}
return JSON.stringify(userInfo);
},
Kindly mark correct and helpful if applicable
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-08-2023 10:19 PM
Hi
there is no need to script anything as the prefilling can be configured for your catalog variables:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-08-2023 10:33 PM
yes this one is prefered way, but requirement is to achive scripting only
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-08-2023 10:24 PM
You can achieve this without using script include (with the method of getReference) as below:
var data = g_form.getReference("requestor",mydata);
function mydata(data){
g_form.setValue("location",data.location);
g_form.setValue("phone",data.phone); // please check the fields backend value according to your instance
}
Please update the field values according to your instance, in this case you dont need to call script include,, just mention this code in client script
If my answer solved your issue, please mark my answer as ✅ Correct & 👍Helpful based on the Impact.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-09-2023 12:32 AM
i tried this one but location field i am getting sys_id , so i move to script include.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-09-2023 01:12 AM
Hello @Gillerla Rajesh , Have you tried option posted by me ?