- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2023 12:33 PM
Hey Community,
How can we Store values in JSON format in servicenow in system properties. I want to store multiple values in a single property.
Thanks
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2023 12:36 PM
Hi @SnowUserDev ,
U can do something like this.
{
"key1":"value1",
"key2":"value2",
"key3":"value3"
}
Thanks,
Danish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2023 12:39 PM
Hi @SnowUserDev ,
U can create a property of type string n then put the values in the above format.
Thanks,
Danish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2023 12:42 PM
Hello @SnowUserDev ,
if you share your case, we might find another solution than storing in a property.
you can store it in a string property, just go to Properties and store you JSON in a string property type record.
When you are getting the property anfte you use gs.getProperty('<your_JSON_property') use an JSON.parse
var prop = gs.getProperty('<your_JSON_property')
va yourObject = JSON.parse(prop)
/*you logic here with the Object*/
Hope that this helped, if it does you can mark it as helpful and accept the solution.
All the best,
Stefan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2023 12:47 PM
Hi @SnowUserDev ,
You can try the way which @Stefan Georgiev has suggested just adding 1 more step to it.
If u want to use 1 of the key & its value u can write something like this
var a = yourObject.key1; //this will print the value present in it.
Thanks,
Danish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2023 12:42 PM
Hello @SnowUserDev ,
if you share your case, we might find another solution than storing in a property.
you can store it in a string property, just go to Properties and store you JSON in a string property type record.
When you are getting the property anfte you use gs.getProperty('<your_JSON_property') use an JSON.parse
var prop = gs.getProperty('<your_JSON_property')
va yourObject = JSON.parse(prop)
/*you logic here with the Object*/
Hope that this helped, if it does you can mark it as helpful and accept the solution.
All the best,
Stefan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2023 12:48 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-23-2024 04:22 AM
I've tried this and give me this error
com.glide.RhinoEcmaError Unexpected token:0
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2023 12:43 PM
Hey @SnowUserDev,
I assume that you want this feature for your custom application which will you use. You can create a choice option JSON for Type in the System Property [sys_properties] table. As it is not there out-of-the-box.
You can use it in your properties. Make sure you store the correct formatted JSON value in the properties.
Kindly appreciate the efforts of community contributors by marking appropriate response as the correct solution and helpful, this may help other community users to follow the right solution in the future.
Thanks,
Hamza