ArrayUtil throws error in scoped Application- Service portal

sana11
Kilo Guru

Hi All, Here is my server side script in widget to fetch records an remove duplicates.

data.arr=[];
var item=new GlideRecord('sc_req_item');
item.addEncodedQuery('opened_byDYNAMIC90d1921e5f510100a9ad2572f2b477fe');
item.query();

while(item.next()){
data.arr.push(item.cat_item.name.toString());
}
var arrayUtil = new ArrayUtil();
data.arr= arrayUtil.unique(data.arr);
console.log(data.arr);

 

This script works perfect in Global application. But in scoped application am getting error as ArrayUtil undefined, maybe missing global qualifier .

Still ArrayUtil  works fine ,only issue is throwing error.

Any Suggestion to fix it please.

Thanks!

Sindhu K B

1 ACCEPTED SOLUTION

Hi,

for using ArrayUtil in scoped app; please use this

var arrayUtil = new global.ArrayUtil();

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

7 REPLIES 7

Hi,

for using ArrayUtil in scoped app; please use this

var arrayUtil = new global.ArrayUtil();

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hello Sana,

Calling a Global Script from Another Application Scope: A custom application can call a global script include that is public. For example, the ArrayUtils script include is in the global scope and must be fully qualified when accessing its functions:

<source lang="javascript"> var switches = new global.ArrayUtil(); switches.contains(ary, item); </source>

Minor modification to the script shared by Alberto.

dataArr=[];
var item=new GlideRecord('sc_req_item');
item.addEncodedQuery('opened_byDYNAMIC90d1921e5f510100a9ad2572f2b477fe');
item.query();

while(item.next()){
dataArr.push(item.cat_item.name.toString());
}
var arrayUtil = new global.ArrayUtil();
var data = arrayUtil.unique(dataArr);
console.log(data);

- Pradeep Sharma