Debug GlideAjax Catalog Client Script and Associated Script Include
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-17-2022 09:06 AM
I am a GlideAjax beginner so I am still lost even with the resources available on the topic. Below are the two scripts I am trying to debug. For context, in my catalog item I have a reference variable "suspended_user "that references the sys_user table. I am trying to autopopulate on change another variable "suspended_user_racfid" solely based on the user chosen for the suspended_user variable. Currently, the variable is returning null values when I try to change the suspended_user. Please edit and help debug the client script and script include. Both variables and the client script are within the same variable set within the catalog item.
Client Script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax('ScriptSuspendedRacfID');
ga.addParam('sysparm_name', 'getUserDetails');
ga.addParam('sysparm_suspended_user_racfid', newValue);
ga.getXML(getFunction);
function getFunction(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
g_form.setValue('suspended_user_racfid', answer);
}
}
Script Include:
var ScriptSuspendedRacfID = Class.create();
ScriptSuspendedRacfID.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getUserDetails: function() {
var userId = this.getParameter('sysparm_suspended_user_racfid');
var userName = '';
var mygr = new GlideRecord('sys_user');
mygr.get(userId);
if (mygr.next()) {
userName = mygr.suspended_user;
}
return userName;
},
type: 'ScriptIncludeName'
});
- Labels:
-
Script Debugger
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-17-2022 09:10 AM
If you are loading the record by .get(sys_id) you do not do a .next()
//try. untested.
var mygr = new GlideRecord('sys_user');
if (mygr.get(userId)) {
userName = mygr.suspended_user;
}
Vinod Kumar Kachineni
Community Rising Star 2022
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-17-2022 12:08 PM
Hi thanks for your suggestion. I made the change in the script include but still did not populate a value for suspended_user_racfid. Is there any changes that need to be made in the client script that you can suggest?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-20-2022 11:35 AM
is the field name mygr.suspended_user correct?
is it a custom field?
Vinod Kumar Kachineni
Community Rising Star 2022
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-20-2022 11:41 AM
var ScriptSuspendedRacfID = Class.create();
ScriptSuspendedRacfID.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getUserDetails: function() {
var userId = this.getParameter('sysparm_suspended_user_racfid');
var userName = '';
var mygr = new GlideRecord('sys_user');
if (mygr.get(userId)) {
gs.print(mygr.name);
userName = mygr.suspended_user; //check the name of the field
}
return userName;
},
type: 'ScriptSuspendedRacfID'
});
Vinod Kumar Kachineni
Community Rising Star 2022