How to call array from my system property?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks 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
3 weeks ago
Hi @saint
Have you tried JSON.parse method
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks 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
3 weeks 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
3 weeks ago
So then you will have to stored it in a structured way in the way they can be retrieved.
i.e you can stored it in json and then parse it in json.parse so that they can be utilized as an object..
