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

Alberto Consonn
ServiceNow Employee
ServiceNow Employee

Hi Sindhu,

you can use ArrayUtil in scope application, use the following code as example:

var res=[];
var changeArr=[];
var changeTask = new GlideRecord('change_task');
changeTask.addQuery('change_request', current.sys_id);
changeTask.query();
while (changeTask.next())
  {
  changeArr.push(changeTask.assignment_group.manager);
  res.push(current.u_technical_approver_users=changeArr); //
}
var au = new ArrayUtil();
var newChangeArr = au.unique(changeArr);
var newRes = au.unique(res);

If I have answered your question, please mark my response as correct and/or helpful.

Thank you very much

Cheers
Alberto

Thanks for your quick reply.please check my updated post.

Try this code please:

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 ArrayUtil();
var data = arrayUtil.unique(dataArr);
console.log(data);

ArrayUtil is working. But still it throws error.