- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-16-2018 11:19 PM
Hi ,
We have a name value type field ,which has multiple values as below .As per the requirement ,in a modify request ,we may have to modify either one or two name value pair out of all .
For ex ,we may get request to change the value of Geolocation2 to 120 from 80.
Currently ,the code is as below .
var jsonString = request.body.dataString; // Storing the JSON input sent with the request
var parser = new JSONParser();
var parsed = parser.parse(jsonString);
var rel = new GlideRecord ('incident');
rel.name_value= JSON.stringify(parsed.name_value);
As per the existing code , it expects to send all the available name-value pairs along with modified one .
name-value: {"Geolocation1": "60","Geolocation2": "120","Last Ditch Internet": "NewConnection"}.
But if only modified one is sent , remaining gets deleted and only {"Geolocation2": "120"} remains in the record.
But the expectation is , they will send only name-value:{"Geolocation2": "120"} and the remaining pairs should remain the same .
Any suggestions on how can we traverse through these name value pairs.
Thanks.
Solved! Go to Solution.
- Labels:
-
Integrations

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-17-2018 05:19 AM
Hi Divya,
The following operation
rel.name_value= JSON.stringify(parsed.name_value);
will always replace full name-value list with a new one.
To save non-updated pairs, following script could be applied:
for(var name in rel.name_value) {
if (parsed.name_value[name]!=null &&
parsed.name_value[name]!=undefined) {
rel.name_value[name] = parsed.name_value[name];
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-17-2018 05:19 AM
Hi Divya,
The following operation
rel.name_value= JSON.stringify(parsed.name_value);
will always replace full name-value list with a new one.
To save non-updated pairs, following script could be applied:
for(var name in rel.name_value) {
if (parsed.name_value[name]!=null &&
parsed.name_value[name]!=undefined) {
rel.name_value[name] = parsed.name_value[name];
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-18-2018 02:02 AM
Thanks ScienteSoft .This has helped us .
Another query if there is a new name-value received ,how can we update that.
Thanks.