Attach email attachment to incident
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2023 09:14 AM
I have created a flow that will create a incident based on inbound email. However I am not sure how to attach the attachments from the email to the incident. Any suggestions?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2023 10:55 AM
To attach attachments from an inbound email to an incident in ServiceNow using a Flow, you can follow these general steps:
1. Create an Inbound Email Action in the Flow:
- In your Flow, create an Inbound Email Action that captures incoming emails. Ensure that it's set up to trigger when an email is received.
2. Parse the Email and Extract Attachments:
- Within the Inbound Email Action, use script actions or script steps to parse the email content and extract any attachments. You can use JavaScript to achieve this.
Here's a simplified example of how to extract attachments in Javascript:
var email = current.email; // Assuming 'current.email' contains the email content
// Loop through email attachments
for (var i = 0; i < email.attachment_count; i++) {
var attachment = email.getAttachment(i);
var fileName = attachment.getName();
var fileContent = attachment.getContent();
// Create an attachment record in ServiceNow
var attachmentRecord = new GlideEmailAttachment();
attachmentRecord.table_name = 'incident'; // Set the target table (e.g., 'incident')
attachmentRecord.table_sys_id = incidentSysID; // Set the sys_id of the incident record
attachmentRecord.file_name = fileName;
attachmentRecord.content_type = attachment.getContentType();
attachmentRecord.write(fileContent);
}
In this example, 'incidentSysID' should be replaced with the sys_id of the incident record you're creating.
3. Complete the Flow:
- Continue with the rest of your Flow, which should include creating the incident record and any other necessary actions.
4. Testing and Validation:
- Test the Flow thoroughly to ensure that attachments from inbound emails are successfully attached to the corresponding incident records.
Remember to adjust the code and Flow configuration based on your specific requirements and ServiceNow instance setup. Additionally, consider error handling and validation to handle various scenarios and ensure the attachments are properly linked to the incidents.