getXMLAnswer already with null value
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2023 07:20 PM
I used the scripts as below, I cannot show the expected value, and with the alert(roles) to show what the script could get, it always pop up with "null", can anybody suggest what the issue is of my scripts? much appreciate!
1. Include script:
var MIT_CIMApps_Utils = Class.create();
MIT_CIMApps_Utils.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
// GlideRecord to get Business Apps related Roles
GetBusinessAppRoles: function(){
var role ='';
var businessapp = this.getParameter('sysparm_business_app');
var tableGr = new GlideRecord('cmdb_ci_business_app');
tableGr.addQuery('name',businessapp);
tableGr.query();
if(tableGr.next())
{
role=tableGr.getValue('u_available_roles');
}
return role;
},
type: 'MIT_CIMApps_Utils'
});
2. Client script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax('MIT_CIMApps_Utils'); //name of script include
ga.addParam('sysparm_name', 'GetBusinessAppRoles'); //name of function on script include
ga.addParam('sysparm_business_app', newValue); //name of field on form triggering call
ga.getXMLAnswer(_handleResponse);
// callback function for returning the result from the script include
function _handleResponse(answer) {
var roles = answer;
alert(roles);
}
}
1 REPLY 1
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-04-2023 03:33 AM
Hi,
You have an onChange client script - question: what is the field type that this CS is monitoring?
ga.addParam('sysparm_business_app', newValue); //name of field on form triggering callIf this is reference then "newValue" returns sys_id of selected record but in your Script Include you are building a query based on "name":
tableGr.addQuery('name',businessapp);
Double check what exactly you are passing to server side script and start from there.
