- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-13-2023 09:24 AM
Hello! Currently in the process of learning ServiceNow development, working through a course on Udemy. Here is the script the instructor has. I wrote it line by line, but my script keeps returning "null". Advise?
UI Page:
var checkIncident = setInterval(function() {
processRequest();
}, 5000);
function processRequest () {
var ga = new GlideAjax('ServiceNow201GlideAjax');
ga.addParam('system_name', 'getIncidentStatus');
ga.addParam('sysparm_incident_number', 'INC0000003');
ga.getXML(ajaxProcessor);
}
function ajaxProcessor(response) {
var answer = response.responseXML.documentElement.getAttribute('answer');
console.log('Status: ' + answer);
}
Script Include (client callable):
var ServiceNow201GlideAjax = Class.create();
ServiceNow201GlideAjax.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getIncidentStatus: function() {
var incidentNumber = this.getParameter('sysparm_incident_number');
if(!gs.nill(incidentNumber)) {
var incidentGR = new GlideRecord('incident');
incidentGR.get('number', incidentNumber);
return incidentGR.state.getDisplayValue();
} else {
return 'No incident was found.';
}
},
sayHello: function() {
return "Hello world!";
},
type: 'ServiceNow201GlideAjax'
});
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-13-2023 09:34 AM
Hi,
the parameter is incorrect in line ga.addParam('system_name', 'getIncidentStatus'); it should be sysparm_name
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-13-2023 09:34 AM
Hi @Harvey
I found small spelling mistake in nil().
Script Include (client callable):
var ServiceNow201GlideAjax = Class.create();
ServiceNow201GlideAjax.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getIncidentStatus: function() {
var incidentNumber = this.getParameter('sysparm_incident_number');
if(!gs.nil(incidentNumber)) {
var incidentGR = new GlideRecord('incident');
incidentGR.get('number', incidentNumber);
return incidentGR.state.getDisplayValue();
} else {
return 'No incident was found.';
}
},
sayHello: function() {
return "Hello world!";
},
Also I am assuming that you also have Incident with number 'INC0000003' . Else user correct Incident Number based on your instance.
Thanks
Anubhav Ritolia
ServiceNow Rising Star 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-13-2023 09:34 AM
Hi,
the parameter is incorrect in line ga.addParam('system_name', 'getIncidentStatus'); it should be sysparm_name

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-13-2023 09:35 AM
There are a number of possibilities on why you are getting a NULL. So to troubleshoot I would add a console.log(response) statement to your ajaxProcessor function. That will dump out the whole object and Firefox and Chrome will allow you to poke thru it to see if you are getting what you are looking for.
Then I would add some gs.log() statements to your script include so you can see what its receiving and what your query is returning. Don't forget to add a source to the log statement so you can find them easily, assuming this is not a scoped app. Scoped app you will need to use gs.warn, error or info.