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

@saint 

Hope you are doing good.

Did my reply answer your question?

💡 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

Tanushree Maiti
Giga Sage

Hi @saint ,

Try this.

var propValue = gs.getProperty('list.of.strings');
 
if (propValue) {
     var valuesArray = propValue.split(',');
    var gr = new GlideRecord('your_table_name');
    gr.addQuery('your_field_name', 'IN', valuesArray.join(','));
    gr.query();
    while (gr.next()) 
{
            gs.info("Found record: " + gr.getDisplayValue());
    }
} else {
    gs.warn("System property 'list.of.strings' not found or is empty.");
}
Please mark this response as Helpful & Accept it as solution if it assisted you with your question.
Regards
Tanushree Maiti
ServiceNow Technical Architect
Linkedin:

cohlandt
Tera Contributor

If you trying to do assume each value has two parts try this script. I used Code and Description but you can change those and set them to other things as well not just gs.info.

 

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

if (titles) {

var titlesArray = titles.split(',');

for (var i = 0; i < titlesArray.length; i++) {

var value = titlesArray[i].trim();
gs.info('Full Value: ' + value);

// Optional: split number and description
if (value.indexOf(' - ') > -1) {
var parts = value.split(' - ');
var code = parts[0].trim();
var description = parts[1].trim();

gs.info('Code: ' + code);
gs.info('Description: ' + description);
}
}
}

You can use the split value as '","'