GlideAjax and AbstractAjaxProcessor

MPD
Giga Contributor

I am attempting to call a script include from   a client script.   The script include is working in both one of my business rules and from a UI Action.   I made modifications for the script include to include the GlideAjax constructor then created the Client Script to use the AbstractAjaxProcessor.   As soon as I do this I get the error shown below.   I was sure to check the client callable checkbox.     I am working within the scope of an application and tried both options of the Accessible from field, (i.e. "All Application Scopes" and "This Application Only"), with no luck.

After attempting to troubleshoot my script I thought I would try the one from the Wiki article.   The very simple "HelloWorld" example.   I was thinking this and some of the other examples might shed light on where I went wrong.   Low and behold I get the same error and a null message for my response.   I am attempting this in a Fulji instance in an onChange client script. At one point I even copied and pasted the code "as is" from the Wiki and tried that, but unfortunately it too returned this error.   Below is the code I am currently attempting to get working.   Does anyone have a clue as to what the issue might be ? ... this is as simple as it gets.

find_real_file.png

Client Script:

function onChange(control, oldValue, newValue, isLoading, isTemplate) {

if (isLoading || newValue == '') {

  return;

}

var ga = new GlideAjax('ATest'); // I believe this should define the processor from the script include

ga.addParam('sysparm_name','helloWorld');

ga.addParam('sysparm_user_name',"Bob");

ga.getXML(HelloWorldParse);

function HelloWorldParse(response) {

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

  alert(answer);

}

}

Script Include:

var ATest = Class.create();

ATest.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    helloWorld: function() {

          return "Hello " + this.getParameter('sysparm_user_name') + "!";

    },

type: "ATest"

});

1 ACCEPTED SOLUTION

sidarth
Giga Expert

Hi Michael D'Amico


A slight change in your script include.



When you are writing script include in application scope please include global.AbstractAjaxProcessor



var ATest = Class.create();


ATest.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {


    helloWorld: function() {


          return "Hello " + this.getParameter('sysparm_user_name') + "!";


    },


type: "ATest"


});



Let me know if it was helpful


View solution in original post

17 REPLIES 17

Can you let me know if you are using this in an application scope and whether client callable is selected?


s_kumar
Mega Contributor

hey Sidarth ..


My application scope is global ..... and yes i have checked client callable check box ...


and i am also not getting any error   but the output i am getting is NULL


Just remove the global. Refer to the modified script below:



var counttest = Class.create();


counttest.prototype = Object.extendsObject(AbstractAjaxProcessor, {


      counttest: function() {


              gs.info ('AAAA:This script is executing');


              var gr = new GlideRecord('incident');


              gr.query();


              if(gr.next())


                      { //Added this one


  gs.info("info");


              var datedif = gs.dateDiff(gr.sys_created_on,gs.nowDateTime(), false);


              gs.info('AAAA:'+datedif);


              return datedif;


      }


},


type: 'counttest'


});


s_kumar
Mega Contributor

Hi sidarth,



I have tried your script but now its giving following results.


1.PNG


which servicenow version are you using?