- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-16-2020 06:26 AM
Hi Team,
Im getting into a huge trouble here, Any help please on resolving this?
obj.prop1.Catalog_item = "Get me a Tennis racquet";
Constructed JSON-----{"prop1":{"requested_for":"Roger Federer","Catalog_item":"Get me a Tennis racquet"},"prop2":"Test"}
var Arr2 = ["y1","y2"];
{
obj.prop1.Arr1[i]=Arr2[i]; // Something like this it has to be , the Object value has to be dynamic.
}
var json = JSON.stringify(obj);
Constructed JSON-----{"prop1":{"x1":"y1","x2":"y2"},"prop2":"Test"}
Can anyone please help me with the above pleaseee
Thanks in advance !
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-16-2020 06:35 AM
Hi Vidya,
try this script and it should work; i tried in background script;
I assume both the array at any point of time would have same number of values
var obj = {};
var Arr1 = ["x1","x2"];
var Arr2 = ["y1","y2"];
var obj1 = {};
for(var i=0;i<Arr1.length;i++)
{
obj1[Arr1[i]] = Arr2[i].toString();
}
obj.prop1 = obj1;
obj.prop2 = "Test";
gs.info(JSON.stringify(obj));
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-16-2020 06:35 AM
Hi Vidya,
try this script and it should work; i tried in background script;
I assume both the array at any point of time would have same number of values
var obj = {};
var Arr1 = ["x1","x2"];
var Arr2 = ["y1","y2"];
var obj1 = {};
for(var i=0;i<Arr1.length;i++)
{
obj1[Arr1[i]] = Arr2[i].toString();
}
obj.prop1 = obj1;
obj.prop2 = "Test";
gs.info(JSON.stringify(obj));
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-16-2020 06:28 PM
Thanks a lot for this.
This saved my work.
Many thanks !