Interested in a ServiceNow event built for developers? Registration for now[dev]26 is officially open!

error when calling Ajax from background script

Mohamed Taha
Tera Expert

I have a Script-include called TaskUtilAjax and I'm trying to call this ajax from background script using the below code 
and gets me this error 
"GlideAjax" is not defined
var ajax =new GlideAjax('TaskUtilAjax');
ajax.addParam('sysparm_name', 'canClode');

ajax.addParam('releaseTask_rec', ' sys_id Value')

ajax.getXML(callback);

var answer;

function callback (response){

    answer = response.responseXML.documentElement.getAttribute("answer");

gs.print(answer);
}

if it helps , I'm in the global scope and make sure the script include is active 

3 REPLIES 3

SN_Learn
Mega Patron

Hi @Mohamed Taha ,

 

You can test it in the background script as below:

new NameOfScriptInclude().NameOfFunction();

 

Example: 

var number = new DateTimeUtils().int8ToGlideDateTime();
gs.info(number);

Here, DateTimeUtils is the 'ScriptInclude' name and 'int8ToGlideDateTime' is the function name.

 

 Please mark this response as correct or helpful if it assisted you with your question.

----------------------------------------------------------------
Mark this as Helpful / Accept the Solution if this helps.

Abhit
Tera Guru

@Mohamed Taha  - You got to make some changes in the script include so that it can be called from both client and server side.

see the Sandeep's response : https://www.servicenow.com/community/developer-forum/how-to-execute-client-callable-script-include-i...

 

 

Not applicable

Hi @Mohamed Taha ,

 

Just check for 2 things,

 

1. See if the Script include is created with exact same name.

2. Make sure that your Script include is in Global scope and Client callable check box is true...

 

use the below script to get the value to be printed:

in glide ajax use return answer;

var val = new NameOfScriptInclude().NameOfFunction();
gs.print(val);