- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-03-2020 09:05 AM
Hi Everyone,
How do I loop through the choices in a system property? I have a script include which populates a list of Hardware assets. What I then want to do is is check the model category of the asset against the choices in a system property and only display the ones that match.
So for example if the system property has the choices of desktop,Laptops,smartphones. I want to be able to check the Model Category of each returned asset to see if it matches one of the three choices so the list shows only Desktops, Laptops and Smartphones.
I know I can use gs.getProperty() to get the value but how do I cycle through the choices?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-03-2020 09:09 AM
HI,
One way would be to do something like below
var str = gs.getProperty('<your Property>');
var arr = str.split(',');
for(var i=0;i<arr.length;i++)
{
//arr[i] gives you one value from property, like smartphone, do whatever with it.
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-03-2020 09:09 AM
HI,
One way would be to do something like below
var str = gs.getProperty('<your Property>');
var arr = str.split(',');
for(var i=0;i<arr.length;i++)
{
//arr[i] gives you one value from property, like smartphone, do whatever with it.
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-03-2020 09:24 AM
something like this
var propertyValue = gs.getProperty('model.category.choices');
var rec = new GlideRecord('alm_hardware');
rec.addQuery('Your query here');
rec.query();
while(rec.next()){
var value = rec.model_category.getDisplayValue();
if(propertyValue.indexOf(value) > -1){
gs.info('Matching one of the choices from property value');
}
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-04-2020 02:34 AM
Thanks for the answers guys. I will try them out and let you know.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-04-2020 02:59 AM
Thanks again guys i have tried the solutions and i think
I think the key to understanding this is that it is easier to use the system property value as a comma separated list than it is to put that data into the choices field. Then use that to populate an array.
Still not sure but maybe the choices are meant to be cycled through or used to set the property or if they are simply intended to just populate a choice list with generic choices.
Thanks again guys for the speedy answer even though I'd clocked off for the day 🙂