Can we store different type of value in a single system property

UTSAV KUMAR JAI
Tera Contributor

Hello Everyone

I wanted to store values such as "1", "one", "One" (digit & Alphabet) in a single system property.
Can this approach is feasible??


Thanks in advance
Utsav

7 REPLIES 7

Dr Atul - LNG
Tera Patron

Hi @UTSAV KUMAR JAI 

What is your exact use case for this? I think we can store it, as we have a property where multiple assets can be stored in one property. It really depends on your specific use case.

Hello, @Dr Atul - LNG  See, my usuage is like--

var va1 = "one";
    var mappingJson = gs.getProperty('test.qwerty');
    var mapping = JSON.parse(mappingJson);
    if (va1 == mapping) {
        gs.addInfoMessage("System Property is working");
    }

Here, the variable "va1" can have any value like---1, one, One, 2, Two, two etc.

And I have created a system property with:-

Type as String
Value as---{"1","one","One","2","Two","two"}

but based on the above mentioned code, it is not working.

Need suggestions
Regards
Utsav

Rafael Batistot
Mega Patron

Hi @UTSAV KUMAR JAI 

 

Yes — a system property in ServiceNow is always stored as a string, so you can save "1", "one", and "One" in the same property (usually comma-separated or JSON format). But the platform won’t automatically interpret them as different types; you’ll need to parse and handle them in your scripts.

 

Feasible, but not recommended if you need multiple formats. Better to define one consistent format or use multiple properties.

 

It’s not a good practice.

System properties are meant to hold a single, consistent value (string, boolean, number, or JSON). Mixing different formats like "1", "one", "One" in the same property makes your scripts harder to maintain, error-prone, and confusing for others

Ajay_Chavan
Kilo Sage

Yes, this is feasible in ServiceNow. Use JSON format in a system property.

Example Setup:
System Property: x_custom.number_mapping
Value: {"1":"one","2":"two","3":"three"}

Script to Get Value:
// Get system property and parse JSON
var mappingJson = gs.getProperty('x_custom.number_mapping');
var mapping = JSON.parse(mappingJson);

// Usage
var result = mapping['1']; // Returns: "one"
gs.info(result);




Benefits: Easy to maintain, supports multiple formats, centralized configuration.