- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2023 12:54 AM
Hi all,
I have four variables. category, sub category, service and service offering.
Category and sub category are single line text.
Service and Service offering are reference to respective tables.
I have an existing JSON object which is stored in a system property.
JSOn is like below:
{
"apps": {
"Corporate - Learning Platform": {
"service": "18a39f9dc34a2190a0135c3ce00131ad",
"offering": ""
},
"Corporate - Oracle EPM (Enterprise Performance Management)": {
"service": "71b26be7479c6d102bb635a2e36d435c",
"offering": ""
},
"Corporate - Oracle ERP (Enterprise Resource Planning)": {
"service": "7db22be7479c6d102bb635a2e36d4385",
"offering": ""
},
"Corporate - ATS -Recruitment Platform": {
"service": "0542e69dc3462190a0135c3ce0013134",
"offering": ""
},
},
}
in above JSON, apps is category and Corporate is sub category.
Requirement: when end user fills all four variables and submits the catalog item. I have to create a new JSON inside the JSON. Similar to apps.
I'm calling a script include from flow using action. Inside action I'm passing all variables.
I have tried like below:
var jsonObject = new GlideRecord('sys_properties');
jsonObject.get('858b9c2847c6ed502bb635a2e36d432b');
var jsonValue = jsonObject.getValue('value');
var js1 = JSON.parse(jsonValue);
//
var js4 = JSON.stringify(js1);
jsonObject.value = js4;
jsonObject.update();
Please help me on how to add an new object in this system property.
For example, if end user submits variable like:
category: servicenow
subcategory: developer
service: 89677iu4hkhoiusknfukhfouehoh
service offering: ilhuihur79297skfiowur09328094
I have to create a new object. Any help?
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2023 03:50 AM
@Naga Ravindra R Update your code as follows.
updateJSON: function(addCat, addSubCat, addService, addOffering) {
var jsonObject = new GlideRecord('sys_properties');
jsonObject.get('858b9c2847c6ed502bb635a2e36d432b');
var jsonValue = jsonObject.getValue('value');
var js1 = JSON.parse(jsonValue);
var innerJSON = {};
innerJSON["service"] = addService;
innerJSON["offering"] = addOffering;
var someObj = {};
someObj[addSubCat] = innerJSON;
js1[addCat] = someObj;
var js3 = JSON.stringify(js1);
jsonObject.value = js3;
jsonObject.update();
},
Please don't forget to mark my answer correct and helpful.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2023 04:42 AM
@Naga Ravindra R Please update your code as follows.
var jsonObject = new GlideRecord('sys_properties');
jsonObject.get('858b9c2847c6ed502bb635a2e36d432b');
var jsonValue = jsonObject.getValue('value');
var js1 = JSON.parse(jsonValue);
var innerJSON = {};
innerJSON["service"] = '89677iu4hkhoiusknfukhfouehoh';
innerJSON["offering"] = 'ilhuihur79297skfiowur09328094';
js1['servicenow']={'developer':innerJSON};
var js4 = JSON.stringify(js1);
jsonObject.value=js4;
jsonObject.update();
Please mark this answer helpful and correct if it manages to address your requirement.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2023 01:52 AM
Hello @Sandeep Rajput
Thank you so much for replying.
I changed my scipt like below:
updateJSON: function(addCat, addSubCat, addService, addOffering) {
var jsonObject = new GlideRecord('sys_properties');
jsonObject.get('858b9c2847c6ed502bb635a2e36d432b');
var jsonValue = jsonObject.getValue('value');
var js1 = JSON.parse(jsonValue);
var innerJSON = {};
innerJSON["service"] = addService;
innerJSON["offering"] = addOffering;
js1[addCat] = {addSubCat: innerJSON};
var js3 = JSON.stringify(js1);
jsonObject.value = js3;
jsonObject.update();
},
When I tried to with above inputs in variables. the object is updating incorrectly.
Please see below:
Can you please help me on this? Thanks a lot.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2023 03:50 AM
@Naga Ravindra R Update your code as follows.
updateJSON: function(addCat, addSubCat, addService, addOffering) {
var jsonObject = new GlideRecord('sys_properties');
jsonObject.get('858b9c2847c6ed502bb635a2e36d432b');
var jsonValue = jsonObject.getValue('value');
var js1 = JSON.parse(jsonValue);
var innerJSON = {};
innerJSON["service"] = addService;
innerJSON["offering"] = addOffering;
var someObj = {};
someObj[addSubCat] = innerJSON;
js1[addCat] = someObj;
var js3 = JSON.stringify(js1);
jsonObject.value = js3;
jsonObject.update();
},
Please don't forget to mark my answer correct and helpful.