- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 weeks ago - last edited 4 weeks ago
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
3 weeks ago
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 weeks ago
Hi @Rosy14,
have you logged your script include to see if it's triggered?
/* If my response wasn’t a total disaster ↙️ ⭐ drop a Kudos or Accept as Solution ✅ ↘️ Cheers! */
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 weeks ago
it is not triggering. How to fix it?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 weeks ago
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
4 weeks ago
Still not calling