Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

Background script help - array

chidanandadhath
Kilo Guru

I have the below background script, which will display matching Short description. I'm not getting the output properly

var arr = [];
var regex = /SAP/i;
var strSD='';
var stdDesc='';
var gr = new GlideRecord('incident');
gr.query();
while (gr.next())
{
strSD= gr.short_description;
if(regex.test(strSD))
{
arr.push(strSD);
gs.info(arr);

}

}

 

 

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

following is the updated script; use toString()

you should print the array outside the while loop to get the final array

var arr = [];
var regex = /SAP/i;
var strSD='';
var stdDesc='';
var gr = new GlideRecord('incident');
gr.query();
while (gr.next())
{
strSD= gr.short_description;
if(regex.test(strSD))
{
arr.push(strSD.toString());
}
}

gs.info(arr);

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

1 REPLY 1

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

following is the updated script; use toString()

you should print the array outside the while loop to get the final array

var arr = [];
var regex = /SAP/i;
var strSD='';
var stdDesc='';
var gr = new GlideRecord('incident');
gr.query();
while (gr.next())
{
strSD= gr.short_description;
if(regex.test(strSD))
{
arr.push(strSD.toString());
}
}

gs.info(arr);

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