Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

getXMLAnswer already with null value

lindian li
Tera Contributor

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

pablo_itguy_pl
Mega Guru

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 call

If 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.