Best practice for updating/inserting a new key/value pair in the additional_info field in em_alert
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2023 05:22 PM
Hi All... long time reader, first time poster.
I need some guidance in regards to the best approach/practice for updating the value of an existing key/value pair in the Additional Info field of an Alert (em_alert) record and inserting a new key/value pair to the same field.
We have a Business Rule running before insert of Alert records which parses the Additional Info key/values and outputs new ones (it enriches the Alert based on another table).
So far we have been using JSON.parse() to process the values in the "Additional Info" field, add new keys/values to the object and then use JSON.stringify() to update the field with the new string, but we've noticed that the output of stringify is slightly different to what is produced OOTB (it is basically missing the space before the ":")
We would like to keep the value of Additional Info standard.
We can .replaceAll('":','" :') but I imagine there must be a function that will produce the standard, OOTB "format" of that field.
Any ideas appreciated.
Cheers...
Pablo.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2025 06:35 AM
Hello @Pablo Garbarino
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2025 12:32 PM
Well, I'd probably recommend adding it via Event Rule, or Field Mapping, but if BR is what you need, I have used a couple options in the past, not sure what's best, but let you decide:
1.- additional_info is a string field so you can manipulate it as any string.
GR.setValue('additional_info',GR.getValue('additional_info').replace(/\n}$/,',\n "new_key" : "new value"\n}'));
2.- the one from the post... parse the JSON string, add the key/value, stringify updating the string to match how alerts
var addinfoObj=JSON.parse(GR.getValue('additional_info'));
addinfoObj['new_key'] = 'new value';
Cheers...
Pablo.