How to call array from my system property?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
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!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
Hi @saint
Have you tried JSON.parse method
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
Hello @saint ,
First of all stored the values in total string format -> "111 - TEST,112 - Test2" (comma seperated),
depending on how you’ve stored it. To work with it as an array, split it:
var titlesArray = titles.split(',');
so after retriving you will get as -> ["111 - TEST", "112 - Test2"]
Then use it according to your requirement in gliderecord :
var gr = new GlideRecord('<table>');
gr.addQuery('your_field', 'IN', titlesArray.join(','));
gr.query();
while (gr.next()) {
//perform your further operation
}
If my response helped mark as helpful and accept the solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
an hour ago
I do have lots of values with "," in the values like "111- Test,One", "112- Test,Ten", that's the reason i'm unable to use this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
an hour ago
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
