Is it Possible to Add a Comment When an Email Attachment is Discarded

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2024 05:01 AM
Hi everyone,
I'm working on an inbound action in ServiceNow that creates tickets from incoming emails. I have a requirement where if an email attachment is discarded during the ticket creation process, I want to add a comment to the ticket indicating that the attachment was discarded.
Is this possible? If so, can someone please share the steps or script involved?
I've tried searching the community and documentation but haven't found a definitive answer. Any help or suggestions would be greatly appreciated.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2024 08:32 AM
Hi @Community Alums ,
Try with below code.
// Assuming 'email' is your incoming email object
var gr = new GlideRecord('incident'); // Change 'incident' to your target table
gr.initialize();
gr.short_description = email.subject;
// Other ticket fields here
// Check for attachments
var attachment = new GlideSysAttachment();
var attachments = attachment.getAttachments(email.sys_id);
if (attachments) {
gr.comments = "An attachment was discarded during ticket creation.";
}
// Insert the record
var ticketSysId = gr.insert();
-------------------------------------------------------------------------
If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.
Regards
Runjay Patel - ServiceNow Solution Architect
LinkedIn: https://www.linkedin.com/in/runjay
YouTube: https://www.youtube.com/@RunjayP
-------------------------------------------------------------------------