The CreatorCon Call for Content is officially open! Get started here.

UI Page using GlideAjax in Client returning null

brian4500
Kilo Contributor

Hello,

First time posting here and new to ServiceNow! My issue is with my UI Page's Client Script/Script Include returning a null answer for the value.

The basic goal of the code is to change an HTML button red/amber/green based on if the query is hitting true. I'm trying to return true/false and test that inside the client, essentially making the server do the heavy lifting of running the queries and then testing the results it pushes back. The code I have posted here is for the red color change condition only.  

Client Script in UI Page

$ = jQuery.noConflict(true);

$( document ).ready(function() {

    //Type appropriate comment here, and begin script below

var a = new GlideAjax('TOER_color_change');

a.addParam('sysparam_name','redColor'); //calling the function in the client script

a.getXMLAnswer(red_color_check);

console.log('run');

function red_color_check(response)

{

var answer = response;

console.log('r_answer: '+answer);

if(answer == true)

$('#VNTV').css('background-color','red');

}

});

Script Include

var TOER_color_change = Class.create();

TOER_color_change.prototype = Object.extendsObject(AbstractAjaxProcessor, {

redColor:function()

{

var rd = new GlideRecord('u_bcm_incident');

rd.addEncodedQuery('active=true^priorityIN1,2^u_caused_by=1');

rd.query();

var r_result = false;

if(rd.next())

r_result =   true;

return   r_result;

},

type: 'TOER_color_change'

});

When I console log ["r_answer: " +result] it gives me null every time. I've read through quiet a few threads on here including this one which was similar but I'm still getting null!

8 REPLIES 8

brian4500
Kilo Contributor

Here is the code a little easier to read:




Client Script in UI Page


$ = jQuery.noConflict(true);


$( document ).ready(function() {


    //Type appropriate comment here, and begin script below


var a = new GlideAjax('TOER_color_change');


a.addParam('sysparam_name','redColor'); //calling the function in the client script


a.getXMLAnswer(red_color_check);


console.log('run');



function red_color_check(response)


{


var answer = response;


console.log('r_answer: '+answer);


if(answer == true)


$('#VNTV').css('background-color','red');


}



});



Script Include


var TOER_color_change = Class.create();


TOER_color_change.prototype = Object.extendsObject(AbstractAjaxProcessor, {



redColor:function()


{


var rd = new GlideRecord('u_bcm_incident');


rd.addEncodedQuery('active=true^priorityIN1,2^u_caused_by=1');


rd.query();


var r_result = false;


if(rd.next())


r_result =   true;


return   r_result;


},



type: 'TOER_color_change'


});


You can directly call script include inside the function than querying in script section


Are you talking about calling the script include inside of the function red_color_check?


Brian these link will help you:



Re: How to call script include within ui page



Re: How do I include a script include into a ui page?



GlideAjax - Client



If you are still not able to figure out let me know then I can help you in detail.