The CreatorCon Call for Content is officially open! Get started here.

GlideAjax not working in Scoped Applications

jpavanaryan
Tera Expert

I am trying to call Script Include from UI Script in scoped application. Surprisingly UI script unable to contact with Script Include. Script Include is accessible from all applications.

Ui Script:

function loadMyItineraries3()

{

      var ga = new GlideAjax('loadMyItineraries');

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

  ga.getXML(getResponse);

}  

   

function getResponse(response)

{

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

  alert(responseString);

}

Script include:

var loadMyItineraries = Class.create();

loadMyItineraries.prototype = Object.extendsObject(global.AbstractAjaxProcessor,

{

  loadItineraries : function ()

  {

  gs.log('Inside loadItineraries Function');

      var i=0;

      var list=[];

      var gr=new GlideRecord('XXXXXXXXXXXXXXXX');

      gr.addQuery('entered_by',gs.getUserID());

      gr.query();

      while(gr.next())

      {

    var data=gr.group.getDisplayValue()+'\t'+gr.number+'\t'+gr.traveler.getDisplayValue()+'\t'+gr.post.getDisplayValue()+'\t'+gr.start_date+'\t'+gr.end_date+'\t'+gr.sys_updated_on+'\t'+gr.status+'\n';

  list[i++]=data;

  }

  gs.log('List '+list.toString());

  return list.toString();

  }

});

1 ACCEPTED SOLUTION

coryseering
ServiceNow Employee
ServiceNow Employee

Hi jpavanaryan,



A few things to note:


1. You have a Script Include and UI Script which provides functions that can call that Script Include, using GlideAjax. You still need to get that UI Script onto a form or page. I assume you have a Client Script which loads the UI Script via the ScriptLoader, or that you are using this in a UI Page and have directly added the appropriate <script> tag to that page, to bring the UI Script in?



2. gs.log() is not available to scoped scripts. There is a scoped logging API you can use instead.



3. If you check your node log files when testing the above scripts, as-is, you should find exceptionslike this:


WARNING *** WARNING *** Function log is not allowed in scope x_yourscope. Use gs.debug() or gs.info() instead


com.glide.script.fencing.MethodNotAllowedException: Function log is not allowed in scope x_yourscope. Use gs.debug() or gs.info() instead


at com.glide.script.fencing.ScopedScriptableObject.checkWhitelistAccess(ScopedScriptableObject.java:131)


at com.glide.script.fencing.ScopedScriptableObject.shouldAllow(ScopedScriptableObject.java:99)


at com.glide.script.fencing.WrappedScriptableObject.get(WrappedScriptableObject.java:57)



If you ensure that you are actually bringing your UI Script into the page, and that you are using the Scoped Logging API, your code should work.



Thanks


Cory



[Edited to add links to the scoped logging API]


View solution in original post

6 REPLIES 6

Hi



We are trying to do something similar but are not able to get it to work.



We have Scoped Application with UI Script where we are trying to call a Script include with GlideAjax. We are not able to invoke the function. Is there anything else we need to do to get this to work.



Thanks


Aman Gulati


johnram
ServiceNow Employee
ServiceNow Employee

The ServiceNow Wiki content is no longer supported. Updated information about this topic is located here: Server API Reference




Visit http://docs.servicenow.com for the latest product documentation