System Property key-value not working

UTSAV KUMAR JAI
Tera Contributor

Hello Everyone,

I am having a code as---

    var var1 = "One";
    var mappingJson = gs.getProperty('test.qwerty');
    var mapping = JSON.parse(mappingJson);
    if (var1 == mapping["1"]) {
        gs.addInfoMessage("System Property is working");
    }
    else{
        gs.addInfoMessage("System property is not working");
    }
 
And, in system property side,

Type--String
Value--{"1":"One","one"}


Currently, it is not working, any inputs??

Warm Regards
Utsav
5 REPLIES 5

GlideFather
Tera Patron

Hi @UTSAV KUMAR JAI,

 

not working, how? 🙂

 

Can you please be more specific?

———
/* If my response wasn’t a total disaster ↙️ drop a Kudos or Accept as Solution ↘️ Cheers! */


KrishnaMohan
Giga Sage

Hi @UTSAV KUMAR JAI 

Please check your key value ie. {"1":"One","one"} object is not valid format. Missing  ":"  and value for "one"
{'key1' : 'value1', 'key2' : 'value2',.......}


If you found my response helpful, I would greatly appreciate it if you could mark it as "Accepted Solution" and "Helpful."

Thanks and Regards
Krishnamohan Pyneni
 

Ankur Bawiskar
Tera Patron
Tera Patron

@UTSAV KUMAR JAI 

you want the key name based on value of json?

if yes then do this

1) your JSON is not valid

2) if your property holds this json then update the script as this

var mappingJson = '{"1":"One"}';  // Your valid JSON string
var mapping = JSON.parse(mappingJson); // Convert JSON string to object

// To get the first (and only) key:
var firstKey = Object.keys(mapping)[0]; // This gets "1"

// To get all keys as an array:
var allKeys = Object.keys(mapping); // This gets ["1"]

gs.addInfoMessage("Key is: " + firstKey);

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@UTSAV KUMAR JAI 

Hope you are doing good.

Did my reply answer your question?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader