How to get the Key and value from the System Property in a script include?

Subhashree3
Giga Contributor

Hi All,

I have a system property that has value stored like :

{"US":"United States","CN":"China","CA":"Canada","JP":"Japan"}

I want to access this System property in a script include where the condition needs to be checked as if the Key is 'US', Value should be returned and 'United States'. 

Very new to system properties. Could you all please help me how to resolve this?

Thank you.

1 ACCEPTED SOLUTION

The SN Nerd
Giga Sage
Giga Sage

Here is an example using an OOTB System Property with code run in Xplore

System Property Value

{"REPORT" : "book","MAP" : "image","HOMEPAGE" : "home","SURVEY" : "form","ASSESSMENT" : "form","TIMELINE" : "calendar","SCRIPT" : "script","LIST" : "list","DETAIL" : "book-open","NEW" : "add","SEARCH" : "search","LABEL" : "label","HTML" : "script","DIRECT" : "view","NULL" : "help"}

Script

var index = 'REPORT';
var props = gs.getProperty('glide.ui.nav.type_icon_map');
var hashMap = JSON.parse(props); // Add global prefix if in scope
var answer = hashMap[index];

answer; 

Output

book

Replace the system property with your own and the appropriate error checking and you should be good.


ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022

View solution in original post

9 REPLIES 9

The SN Nerd
Giga Sage
Giga Sage

Here is an example using an OOTB System Property with code run in Xplore

System Property Value

{"REPORT" : "book","MAP" : "image","HOMEPAGE" : "home","SURVEY" : "form","ASSESSMENT" : "form","TIMELINE" : "calendar","SCRIPT" : "script","LIST" : "list","DETAIL" : "book-open","NEW" : "add","SEARCH" : "search","LABEL" : "label","HTML" : "script","DIRECT" : "view","NULL" : "help"}

Script

var index = 'REPORT';
var props = gs.getProperty('glide.ui.nav.type_icon_map');
var hashMap = JSON.parse(props); // Add global prefix if in scope
var answer = hashMap[index];

answer; 

Output

book

Replace the system property with your own and the appropriate error checking and you should be good.


ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022

Hi Paul,

The above solution worked fine for one scenario. Thank You for this. However for one more scenario, I need to get the reverse. Means if I give input as "book", output should be "Report" as per your example and we need to maintain this one System property.

Please let me know how it can be done.

Thanks

Hi,

 

Note: Please mark reply as helpful if it has answered your 2nd question

var props = gs.getProperty('glide.ui.nav.type_icon_map');
var hashMap = JSON.parse(props); // Add global prefix if in scope

for ( var v in hashMap ) {

  if ( hashMap[v] == 'book' ) {
    return v; // this will give you the first ocurrence of key
  }
}


It worked! Thank You.