Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

Function X is not allowed in scope Y

wallace
Kilo Contributor

Good day all,

I am busy with creating a custom application and tried to create an application Script Include. I am trying to call a basic function (in this case getFields)

This however gives me an error, what is the correct way of using/create a script like this

Code

var MyScript = Class.create();

MyScript.prototype = {

  initialize: function() {

  },

  test : function(current) {

      var fields = current.getFields();

  },

  type: 'MyScript'

};

Error
Function getFields is not allowed in scope x_company_test
1 ACCEPTED SOLUTION

Artemis15
Kilo Guru

Hi Wallace,



getFields() is a function of GlideElement, which is globally accessible.


See http://wiki.servicenow.com/index.php?title=Scoped_System_API



Another thing, I wanna point out is getFields will work only with glide Objects like GlideRecord object or current in BR.




--


Cheers,


AR


View solution in original post

3 REPLIES 3

Artemis15
Kilo Guru

Hi Wallace,



getFields() is a function of GlideElement, which is globally accessible.


See http://wiki.servicenow.com/index.php?title=Scoped_System_API



Another thing, I wanna point out is getFields will work only with glide Objects like GlideRecord object or current in BR.




--


Cheers,


AR


wallace
Kilo Contributor

Thanks,



used the below and it seems to have fixed my issue


var gr = new GlideRecord('x_company_test_ticket');


gr.addQuery('sys_id',current.sys_id);


gr.query();


Ben Vargas
Tera Guru

Hi All -



Has anything changed with regards to this answer? I'm on a UI Action to test getFields() and both of these fail within my scoped application:



// Fails...


//var fields = current.getFields();


//gs.addInfoMessage('fields: ' + fields);




// Also fails...


var gr = new GlideRecord('x_7940_xyz_customer');


gr.get(current.sys_id);


gs.addInfoMessage('sys_id: ' + gr.sys_id); // good GlideRecord, sys_id displays


var fields = gr.getFields(); // creates error: Function getFields is not allowed in scope x_7940_xyz



Thanks!



Ben