- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-20-2018 07:45 AM
I have a watchlist on a form, and when I query the table to split the values of this field, only a few (5 out of 90) I receive a org.mozilla.javascript.NativeArray@1a1047f error when I try to process the values.
Would be fine if this was static across all records in that table, however, it only occurs on some of the records. I have verified the values in the watchlist field, they are valid references to the user table on a valid one and one that receives the error.
Any one seen this before?
Thanks in advance.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-20-2018 09:07 AM
Try adding toString() before you split
var fac = new GlideRecord('u_facility');
fac.query();
while(fac.next()){
var distlist = [];
var distlistnew = [];
var distlistrem = [];
if(fac.u_watch_list != '') {
distlist = fac.u_watch_list.toString().split(',');
gs.print(distlist); // displays ERROR
var distlistlen = distlist.length;
for(i=0;i<distlistlen;i++){
var usr = new GlideRecord('sys_user');
usr.addQuery('sys_id', distlist[i]);
usr.query();
while(usr.next()) {
if(usr.active == true){
distlistnew = distlistnew + usr.sys_id + ',';
}
else {
distlistrem = distlistrem + fac.u_facility_name + ' - ' + usr.name + ',';
}
}
}
fac.u_watch_list = distlistnew;
fac.update();
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-20-2018 07:52 AM
Hi,
Can you share the script which is causing this error? Seems to be some error because of array.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-20-2018 08:17 AM
Can you post the code here
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-20-2018 08:59 AM
var fac = new GlideRecord('u_facility');
fac.query();
while(fac.next()){
var distlist = [];
var distlistnew = [];
var distlistrem = [];
if(fac.u_watch_list != '') {
distlist = fac.u_watch_list.split(',');
gs.print(distlist); // displays ERROR
var distlistlen = distlist.length;
for(i=0;i<distlistlen;i++){
var usr = new GlideRecord('sys_user');
usr.addQuery('sys_id', distlist[i]);
usr.query();
while(usr.next()) {
if(usr.active == true){
distlistnew = distlistnew + usr.sys_id + ',';
}
else {
distlistrem = distlistrem + fac.u_facility_name + ' - ' + usr.name + ',';
}
}
}
fac.u_watch_list = distlistnew;
fac.update();
}
Now, one thing to note as well, I have ran the exact same code in production and there are no errors. We cloned PRD to TEST about 3 weeks ago, could this be a lost reference to a user record?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-20-2018 09:07 AM
Try adding toString() before you split
var fac = new GlideRecord('u_facility');
fac.query();
while(fac.next()){
var distlist = [];
var distlistnew = [];
var distlistrem = [];
if(fac.u_watch_list != '') {
distlist = fac.u_watch_list.toString().split(',');
gs.print(distlist); // displays ERROR
var distlistlen = distlist.length;
for(i=0;i<distlistlen;i++){
var usr = new GlideRecord('sys_user');
usr.addQuery('sys_id', distlist[i]);
usr.query();
while(usr.next()) {
if(usr.active == true){
distlistnew = distlistnew + usr.sys_id + ',';
}
else {
distlistrem = distlistrem + fac.u_facility_name + ' - ' + usr.name + ',';
}
}
}
fac.u_watch_list = distlistnew;
fac.update();
}
}