- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-02-2025 02:34 AM - edited 09-02-2025 02:35 AM
Hi,
I have a ref type variable. Based on that field the first and last name will be populated. below script is not working. Please help.
Client script :
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax('getAffectedUserDetails');
ga.addParam('sysparm_name', 'getUserFirstName');
ga.addParam('sysparm_user_id', newValue);
ga.getXML(SetFirstName_ref);
function SetFirstName_ref(response) {
var first_name = response.responseXML.documentElement.getAttribute("answer");
g_form.setValue('first_name', first_name);
}
ga = new GlideAjax('getAffectedUserDetails');
ga.addParam('sysparm_name', 'getUserLastName');
ga.addParam('sysparm_user_id', newValue);
ga.getXML(SetLastName_ref);
function SetLastName_ref(response) {
var last_name = response.responseXML.documentElement.getAttribute("answer");
g_form.setValue('last_name', last_name);
}
}Script include:
var getAffectedUserDetails = Class.create();
getAffectedUserDetails.prototype = {
initialize: function() {},
getUserFirstName: function() {
gs.addInfoMessage("test");
var user_sys_id = this.getParameter('sysparm_user_id');
var user = new GlideRecord('sys_user');
user.addQuery("sys_id", user_sys_id);
user.query();
if (user.next()) {
//gs.addInfoMessage(user_sys_id);
return user.getValue("first_name");
}
},
getUserLastName: function() {
var user_sys_id = this.getParameter('sysparm_user_id');
var user = new GlideRecord('sys_user');
user.addQuery("sys_id", user_sys_id);
user.query();
if (user.next())
return user.getValue("last_name");
},
type: 'getAffectedUserDetails'
};
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-02-2025 03:40 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-02-2025 02:37 AM
Hi @Rosy14,
have you logged your script include to see if it's triggered?
This reply is 100 % GlideFather and 0 % AI
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-02-2025 02:43 AM
it is not triggering. How to fix it?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-02-2025 03:00 AM
Hi @Rosy14
Try below script as it is in your script and in your code I have a question if your script include is client callable why script include is not extending from AbstractAjaxProcessor (Which is OOTB while making script include as client callable) as shown below
var getAffectedUserDetails = Class.create();
getAffectedUserDetails.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getUserFirstName: function() {
gs.addInfoMessage("test");
var user_sys_id = this.getParameter('sysparm_user_id');
var user = new GlideRecord('sys_user');
user.addQuery("sys_id", user_sys_id);
user.query();
if (user.next()) {
//gs.addInfoMessage(user_sys_id);
return user.getValue("first_name");
}
},
getUserLastName: function() {
var user_sys_id = this.getParameter('sysparm_user_id');
var user = new GlideRecord('sys_user');
user.addQuery("sys_id", user_sys_id);
user.query();
if (user.next())
return user.getValue("last_name");
},
type: 'getAffectedUserDetails'
});
If this helped to answer your query, please mark it helpful & accept the solution.
Regards,
Krishnamohan
Regards,
KrishnaMohan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-02-2025 03:05 AM
Still not calling
