Get a first look at what's coming. The Developer Passport Australia Release Preview kicks off March 12. Dive in! 

How to call array from my system property?

saint
Tera Expert

Hi everyone,

I'm working with a system property that stores an array of string values, for example:

Property: list.of.strings
Values: "111 - TEST", "112 - Test2"

In my Script Include, I'm retrieving the property like this:

 

var titles = gs.getProperty('list.of.strings');

 

I’d like to use these values to query a table with GlideRecord and filter records based on them.

Has anyone done this before or knows the best way to parse and use these property values in a GlideRecord query?

Thanks!

13 REPLIES 13

Hello @saint ,

 

Just simply change little bit code like 

var titles =  gs.getProperty('list.of.strings');

var titlesArray = titles.replace(/^"|"$/g, '').split('","');

 

then try this 

var gr = new GlideRecord('<table>');

if (titlesArray.length > 0) {
    gr.addQuery('your_field', titlesArray[0]);

    for (var i = 1; i < titlesArray.length; i++) {
        gr.addOrCondition('your_field', titlesArray[i]);
    }
}

gr.query();

 

If this helps you then mark it as helpful and accept as solution.

Regards,

Aditya

Aditya_hublikar_0-1771569374196.png

 that replace method code line will give you output like this.

Hello @saint ,

 

I hope you are doing well . Does my response helps you ?

 

If this helps you then mark it as helpful and accept as solution.

Regards,

Aditya

Anand Kumar P
Tera Patron

Hi @saint ,

 

Try below script 

 

var propValue = gs.getProperty('list.of.strings', '');
var spl = propValue.split(',');

for (var i = 0; i < spl.length; i++) {
var gr = new GlideRecord('your_table_name');
gr.addQuery('your_field_name', spl[i].trim());
gr.query();

while (gr.next()) {
gs.info(gr.getDisplayValue('your_field_name'));
}
}

 

If my response helped, please mark it as the accepted solution and give a thumbs up👍.
Thanks,
Anand

Ankur Bawiskar
Tera Patron

@saint 

you are already storing it as string with comma separated values

simply use this

gr.addEncodedQuery('nameIN' + gs.getProperty('list.of.strings'));

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

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