- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-13-2024 03:02 AM
I'm trying to pass incident details to mail body. I've to pass incident record fields to mail body based on assignment group. I'm storing incident fields and values in JSON obj and trying to pass to mail body using ${event.parm2}. I'm getting the data from parm 2 but as obj form. Can anyone help to get the JSON obj data plain text( one field by one field). I have given event queue bellow and previewed mail body.
gs.eventQueue('Event_name', grGroup, arrayGrp, JSON.stringify(parsedArr[y].arr));
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-13-2024 11:25 PM
Hi @Avee90
Please concatenate both the field name and value within the loop.
var incidentFieldsJSON = JSON.parse(event.parm2);
// Construct plain text representation of the incident fields
var plainTextBody = "Incident Details:\n";
for (var key in incidentFieldsJSON) {
if (incidentFieldsJSON.hasOwnProperty(key)) {
plainTextBody += key + ": " + incidentFieldsJSON[key] + "\n";
}
}
email.setBody(plainTextBody);
Please mark my answer helpful and correct.
Regards,
Amit
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-13-2024 03:14 AM
Hi @Avee90
If you're passing a JSON object as a parameter and want to display its contents in plain text format within the email body, you'll need to parse the JSON object and extract its fields and values.
var incidentFieldsJSON = JSON.parse(event.parm2);
var plainTextBody = "Incident Details:\n";
for (var key in incidentFieldsJSON) {
if (incidentFieldsJSON.hasOwnProperty(key)) {
plainTextBody += incidentFieldsJSON[key] + "\n";
}
}
email.setBody(plainTextBody);
Please try this and let me know if it works.
Regards,
Amit
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-13-2024 04:10 AM
Thank you,
It is working but getting only values not getting field names which are in JSON obj.
Output: INC3258000 8 3 2023-12-15 18:31:09 Possible Phishing Incident 0
It should be:
Incident:INC3258000
State: 8
Priority: 3
created: 2023-12-15 18:31:09
Short Description:Possible Phishing Incident
Something like
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-13-2024 11:25 PM
Hi @Avee90
Please concatenate both the field name and value within the loop.
var incidentFieldsJSON = JSON.parse(event.parm2);
// Construct plain text representation of the incident fields
var plainTextBody = "Incident Details:\n";
for (var key in incidentFieldsJSON) {
if (incidentFieldsJSON.hasOwnProperty(key)) {
plainTextBody += key + ": " + incidentFieldsJSON[key] + "\n";
}
}
email.setBody(plainTextBody);
Please mark my answer helpful and correct.
Regards,
Amit