- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-04-2024 10:28 AM
Hi all,
My requirement is in the catalog item if requested for user is selected then the location updated in the requested for user record should populate in location variable. So i was written on change client script and script include to populate. but it was not working. So i am sharing the code i was written below hence kindly someone review the code and help me if i am anywhere wrong.
Script include:
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-05-2024 01:17 AM
@suresh kaliappa If the location is a reference variable then you should return loc.getValue('sys_id'); from script include, instead of loc.full_name;
Please try with the following script include.
var GetUserLocation = Class.create();
GetUserLocation.prototype = Object.extendsObject(AbstractAjaxProcessor, {
GetActiveLocation: function() {
var userId = this.getParameter('sysparm_user');
var userRecord = new GlideRecord('sys_user');
userRecord.get(userId);
if (userRecord.location) {
var loc = new GlideRecord('cmn_location');
loc.get(userRecord.location);
if (loc.u_active == 'true') { // Ensure the custom active field is checked
return loc.getValue('sys_id');
}
}
return ''; // Return empty if no active location found
},
type: 'GetUserLocation'
});
Hope this helps.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-04-2024 10:43 AM
@suresh kaliappa Please check if your script include is a client callable script include. Also is location on your form a string field or a reference field?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-05-2024 12:47 AM
Hi Sandeep ,
location variable is a reference variable.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-05-2024 01:17 AM
@suresh kaliappa If the location is a reference variable then you should return loc.getValue('sys_id'); from script include, instead of loc.full_name;
Please try with the following script include.
var GetUserLocation = Class.create();
GetUserLocation.prototype = Object.extendsObject(AbstractAjaxProcessor, {
GetActiveLocation: function() {
var userId = this.getParameter('sysparm_user');
var userRecord = new GlideRecord('sys_user');
userRecord.get(userId);
if (userRecord.location) {
var loc = new GlideRecord('cmn_location');
loc.get(userRecord.location);
if (loc.u_active == 'true') { // Ensure the custom active field is checked
return loc.getValue('sys_id');
}
}
return ''; // Return empty if no active location found
},
type: 'GetUserLocation'
});
Hope this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-04-2024 10:43 AM
Hi @suresh kaliappa,
Script Include:
var GetUserLocation = Class.create();
GetUserLocation.prototype = Object.extendsObject(AbstractAjaxProcessor, {
GetActiveLocation: function() {
var userId = this.getParameter('sysparm_user');
var userRecord = new GlideRecord('sys_user');
userRecord.get(userId);
if (userRecord.location) {
var loc = new GlideRecord('cmn_location');
loc.get(userRecord.location);
if (loc.u_active == 'true') { // Ensure the custom active field is checked
return loc.full_name;
}
}
return ''; // Return empty if no active location found
},
type: 'GetUserLocation'
});
Client Script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue === '') {
return;
}
var ga = new GlideAjax('GetUserLocation');
ga.addParam('sysparm_name', 'GetActiveLocation');
ga.addParam('sysparm_user', g_form.getValue('requested_for'));
ga.getXMLAnswer(function(response) {
var location = response;
g_form.setValue('location', location);
});
}
Thank you, please make helpful if you accept the solution.