How update a key value of json
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-24-2020 04:16 AM
Hi All,
I have a multi-variable set and from widget client script i have added a line to read the values, which is returning a Array of JSON object.
$scope.mrv = $scope.page.g_form.getValue('mvs_application_variable_set');
data.mvr=eval($scope.mrv);
c.data.jsonObject= eval($scope.mrv);
console.log(c.data.jsonObject);
//response of c.data.jsonObject
[{
id_new_app: "",
action: "New",
info_app: "Testing1",
app_name: "504f50b71b421010f3d34375cc4bcb6c",
software_name: ""
},
{
id_new_app: "",
action: "New",
info_app: "Testing2",
app_name: "10f3d34504f50b71b4210375cc4bcb6c",
software_name: ""
},
{
id_new_app: "",
action: "New",
info_app: "Testing3",
app_name: "71b4210504f50b10f3d34375cc4bcb6c",
software_name: ""
}]
Now in the above response i need to update the software_name as app_name.
Thanks.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-24-2020 04:34 AM
This is the syntax to 'find and replace' every occurrence. I haven't used it in a widget, so you might need different notation at the beginning, but you get the idea
$scope.mrv = $scope.mrv.toString().replace(/software_name/g,'app_name');
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-24-2020 04:55 AM
Hi,
//Assuming that sys_id in app_name to be assigned in software_name.
data.mvr=eval($scope.mrv);
c.data.jsonObject= eval($scope.mrv);
console.log(c.data.jsonObject);
var Data=c.data.jsonObject;
for(var i=0;i<Data.length;i++)
{
var application=Data[i];
application['software_name']=application['app_name'];
}
Please mark it helpful/Correct.
Thanks
Sudhanshu
This link is very helpful:
https://community.servicenow.com/community?id=community_blog&sys_id=865b5aeddbc023c0feb1a851ca9619f9