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
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
that replace method code line will give you output like this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks 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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
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! 🙏
Ankur
✨ Certified Technical Architect || ✨ 10x ServiceNow MVP || ✨ ServiceNow Community Leader
