- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-06-2025 01:44 AM
Hi there,
I have created system property with key value pair. In script I can return value by passing key but is it possible to return key by passing value?
Thanks!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-06-2025 04:25 AM
Resolved:
var propertyValue = gs.getProperty('testproperty');
//{"LATAM":["Argentina", "India", "Brazil"]}
var regionMap = JSON.parse(propertyValue);
var targetCountry = 'India';
for (var region in regionMap) {
var countries = regionMap[region];
if (countries.indexOf(targetCountry) !== -1) {
gs.info("country" + targetCountry + "has region " + region);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-06-2025 03:24 AM
I believe I answered your original question.
In that you didn't mention there would be multiple values in 1 key
but this code should work for you
var prop = '{"LATAM":["Argentina","India","Brazil"],"EU":["UK","France"],"US":"United States"}';
var obj = JSON.parse(prop);
var searchValue = 'India';
var foundKey = null;
for (var key in obj) {
var val = obj[key];
if ((Array.isArray(val) && val.indexOf(searchValue) !== -1) ||
val === searchValue) {
foundKey = key;
break;
}
}
gs.info('Key for value "' + searchValue + '" is: ' + foundKey);
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-08-2025 02:46 AM
Any update to this?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-06-2025 04:25 AM
Resolved:
var propertyValue = gs.getProperty('testproperty');
//{"LATAM":["Argentina", "India", "Brazil"]}
var regionMap = JSON.parse(propertyValue);
var targetCountry = 'India';
for (var region in regionMap) {
var countries = regionMap[region];
if (countries.indexOf(targetCountry) !== -1) {
gs.info("country" + targetCountry + "has region " + region);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-06-2025 04:52 AM
I believe I answered your both the questions the original one and subsequent one.
Any reason you marked your own response as correct?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-08-2025 08:12 PM
Any update to this?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader