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

Rushit Patel2
Tera Guru

Hi Michael,



try var ga = new GlideAjax('global.ATest'); if you are running from global scope. if in scooped app please prefix your app scope.


Hello Rushit,



I tried what you suggested. If I use the application scope I get the same error. If I use global I get a message indicating that application scope is blocking the script call. I actually created two separate script includes, ATest written in my scope, and ATest02 written in the global scope earlier and received the same messages.



I receive a message indicating that "Access to Script Include Global.ATest ..." is blocked from my scope, and the "... may be missing a global identifier" error message whenever I attempt this from my scope. Is there a way to unblock the global scope from within my application ?



The idea is to enable the use of this script include from UI Actions, business rules and client scripts. I don't really care if it's global or not, I just need it to work in my application, but it would be nice to understand why these messages persist. My next step is to investigate the application scope and see if there is a permission or access control of some kind that might need attention. It's all pretty vanilla, I didn't change anything but these messages make me think there might be something I need to address.



I have successfully called my script include from a business rule and a UI Action, but as I've learned GlideAjax must be use in client scripts to call a script include. It appears that when I do get this issue worked out I'll have to change the way I call the script include from both the UI Action and the business rule, and introduce GlideAjax syntax, if I actually want one universal script include for all three script interfaces to function.



Thanks for the suggestion.


Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hi Michael,



You may find the below thread helpful.


GlideAjax: Not able to access function inside script include



Please let me know if you have any questions.


Yes this article is exactly what I am experiencing. The scoping of applications is new in this release and I wonder if there might be an issue with application scopes and script includes.



As mentioned in my earlier post, I created a script include in my scope and in the global scope, (i.e. Atest and Atest02). I recreated the client side script to call the script include for ATest02, (Global scope), from a field change on the Incident form, (also Global scope). Everything worked, I think, because everything was global.



I then changed the client script so that GlideAjax would call the script include from my scope, (i.e. Atest), and nothing happened. I ensured the Access from field of the script include was set to All scopes. It seems to me that this is just broken when it comes to private applications in Fuji. I attempted to change protected mode to read only and then to none. I tested the global setting by including a view name then removed that and re-enabled the global checkbox. I verified all access control permissions were granted, which according to the documentation is where application scope restrictions are enabled. Every permission for the application was granted.



Quite frankly it should work without the global identifier if both scripts are part of the same scope, it did when tested in the global scope. Based on my assessment of the parameters surrounding how the script include is constructed and configured, everything is correct, and based on the fact that the same scripts tested successfully in the global scope makes it appear as if GlideAjax is having an issue with private scopes.



Thanks for the reference ... I thought it was just me at first but it looks like the referenced post you provided is having all the same issues, and like me this person is testing a simple script with the debugger. There is an indication that the function call is simply not working.