UI Page using GlideAjax in Client returning null
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-07-2018 11:34 AM
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!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-08-2018 11:28 AM
Sorry I'm still having issues figuring out how it will work. My console will only display null, I can't get it to produce true/false.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-08-2018 12:02 PM
Brain,
I would go with easy option for now. If you just want to change the field color the you could use this in client script and not UI page client script
function onChange(control, oldValue, newValue, isLoading) {
var elementID = gel("incident.priority");
switch(newValue) {
case "1": elementID.style.backgroundColor = "red"; break;
case "2": elementID.style.backgroundColor = "tomato"; break;
case "3": elementID.style.backgroundColor = "orange"; break;
case "4": elementID.style.backgroundColor = "yellow"; break;
case "5": elementID.style.backgroundColor = "green"; break;
default: elementID.style.backgroundColor = "white"; break; } }
Hope this will help

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-01-2021 12:23 PM
Did you happen to resolve this issue ?? I am running into something similar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-01-2021 12:55 PM
Hi Brian,
Can you try var answer = response.responseXML.documentElement.getAttribute('answer'); in the function red_color_check(response)
function red_color_check(response)
{
var answer = response.responseXML.documentElement.getAttribute('answer');
if(answer == true)
$('#VNTV').css('background-color','red');
}
This will get you the returned value from the script include;
Please mark helpful/correct if this solved your issue.
Thanks,
Ashish