GlideAjax: Not able to access function inside script include

jivanjotkaur
ServiceNow Employee
ServiceNow Employee

I have created a custom application and i am trying to do a GlideAjax, though onSubmit client script , to access a script include within the same scope. I put a debug statement each inside the 'initialize' and 'testfunction' which i am calling in my client script. I found that on execution of the script only the debug statement inside initialize is reflecting in the System Logs. Is the 'testfunction' not getting called at all? The value in the 'answer' variable is also null after execution.

Following is my script include:

Screen Shot 2015-10-04 at 1.40.53 AM.JPG

Corresponding Client Script:

Screen Shot 2015-10-04 at 1.41.32 AM.JPG

20 REPLIES 20

Hi Michael,



Yes, you appear to be calling it correctly. I notice that you're using "new JSON()" in your Script Include. That should be "new global.JSON()" since the JSON Script Include is in the global scope. If you're on Helsinki, you could use "JSON.stringify(object_to_encode)" instead, since JSON is part of the ES5 enhancements added to Helsinki.



If you are on Geneva or older, you need to use the JSON Script Include, which lives in the global scope.


That should be showing up in your node log, when you try to run this code. You should be seeing errors about a missing global identifier. Note that the node log is different from the Script log.



That error could explain why the rest of the include fails to run.


Ok, I did what you suggested...



No luck!



We tried to put the exact same script in the Global App scope, and in the client script referenced the new script Include as global.RCUtilsAJAX.


It worked... Yippee... However not good, as now our app isn't self contained.



Any further ideas?



Regards,


Mike


Hi Michael,



This should be working. Can you send me a private message so we can set up a live debugging session?



Thanks


Cory


Absolutely, as soon as I figure out how to PM, I will...


Hi Michael,



Sometimes it's the simplest things. In this case, it was the gs.log statements in your Script Include. I completely missed that earlier. gs.log is not available within Scoped apps. Instead, we have create new logging methods (gs.info, gs.warn, gs.debug, gs.error). Those are detailed here:


https://wiki.servicenow.com/index.php?title=Scoped_Script_Logging



Note that the variable substitution uses {0},{1} syntax (I think I tried $0,$1 when we were debugging, because it's early and I haven't had any coffee yet).


With that last change to your server-side Script Include, this should work as intended.



Thanks,


Cory