Convert Email Draft to Email
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-06-2025 11:00 AM
I have a requirement to create an email and attach a file to it prior to sending. I thought the best approach might be to use the Draft Email (sys_email_draft) table to 'stage' the email before sending, as opposed to creating a record on the sys_email table and manipulating the 'type' to 'send-ignored' then 'send-ready' once the attachment has been added. I cannot seem to find an elegant solution using an event or triggered notification in which I can programmatically attach a file to the email before it gets sent. For context, I am dynamically generating the file via the MS Excel spoke, and once done, I need to send an email with that new attachment to an external recipient.
The OOB 'Compose Email' button in the workspace opens a modal on the 'record' page with the 'Draft Email Page' variant. The page utilizes the 'NOW Email Client Composer' component which contains the 'Send Email' button, which appears to be embedded in the component itself, as opposed to being a separate UI or Declarative action
I cannot determine what the 'Send Email' button is actually doing to convert the email from a draft to a record on the sys_email table which is then sent. There are no Business Rules or Flows or Scheduled jobs I can tell which are executing to convert the record, so I have to assume code is embedded in the component.
I am looking for some insight into how I might go about doing this conversion from draft to email. Perhaps there is an OOB script include or other logic called from the component which accomplishes this?
Any thoughts/ideas/insights are greatly appreciated!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-06-2025 09:23 PM
Hi @Community Alums ,
Use GlideSysAttachment API and global.EmailUtil script include to convert the draft email to a sys_email record. This script include is part of the OOB functionality and handles the conversion process.
If my response was helpful, please mark it as correct so it can be valuable to others.
Thanks
Jaishree R
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-07-2025 08:01 AM
Thanks for the reply. Can you please be a bit more specific about the 'EmailUtil' script? There is only a single method in that script include, and it doesn't have anything to do with converting a draft to an email.
And as far as using the 'GlideSysAttachment' API, are you suggesting I use that to copy any attachments from the 'sys_email_draft_attachment' table to the 'sys_email_attachment' table? I don't think I'd actually need to copy any attachments, as both of those tables use a reference field to associate the attachment to the draft or email record
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-08-2025 02:50 AM
Hey Timmo,
I am having the same issue, I want to know how ServiceNow converts a draft email to actual sys_email record. Let me know if you find something relevant.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-09-2025 03:24 AM
I am trying to implement the email functionality with custom component.
Generate a Blank Draft:
Use GlideRecord to create a sys_email_draft record with fields like subject, body, and recipient for user updates.
Update Draft on Interaction:
Capture user edits to email fields (e.g., recipients, subject, body).
Dynamically generate attachments and store them in.
Link attachments to the draft using draft email attachments table for reference.
Send Email Logic:
On "Send Email," convert the draft to a sys_email record via GlideRecord.
Copy attachment references from sys_email_draft_attachment to sys_email_attachment.
Sending Email:
Deleting the draft upon successful creation of email records and attachments.
Update the sys_email record state to send-ready. Hoping that the email engine processes and sends sys_email records with state=send-ready through the SMTP server.
Reason for taking this approach
This approach ensures control over the email state and attachment processing. Directly using sys_email risks sending the email before all attachments are processed, as the transition from send-ready to sent is automatic. Using sys_email_draft avoids this issue.
Question:
1. Can someone validate my approach, If not what is the workflow for converting the draft to email ?
2. What specific internal script or API is responsible for transitioning sys_email_draft to sys_email within the NOW Email Client Composer?