- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-02-2017 12:28 PM
We have a business case where users can not log into the system to get the attachment so a link will not work. I have a workflow with some automation in it that will determine which of 3 possible attachments a person will need. However, I can't figure out how to script the attachment to the request item before it triggers the email (by way of event) that will put the attachment on the request item. The email notification has the "include attachments" is checked so when this is triggered it should send the correct attachment with the email. This is because the attachment was put on the request item itself and not trying to add the attachment directly to the email by email script. Again hyperlinks to the system will not work with this business case.
My question is can someone help me with a script to add an attachment to a request item by way of a script in the workflow?
Also is this best way to do this or is there a better way to do it that doesn't have a hyperlink that they will have to log into?
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-02-2017 12:36 PM
Attachments have three main tables: your task table, for the sys_id; the sys_attachment_table, to relate the attachment and task record; and you sys_attachment_doc table, which is the actual body of the attachment (base64). Knowing that, I would put all three attachments on a record and sort out what records it created in sys_attachment and sys_attachment_doc. Knowing that, I would either use the attachment API (https://docs.servicenow.com/bundle/jakarta-servicenow-platform/page/integrate/inbound-rest/concept/c...) to post it via web services, or I would script it to just duplicate those records for any of the three attachments needed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-02-2017 12:36 PM
Attachments have three main tables: your task table, for the sys_id; the sys_attachment_table, to relate the attachment and task record; and you sys_attachment_doc table, which is the actual body of the attachment (base64). Knowing that, I would put all three attachments on a record and sort out what records it created in sys_attachment and sys_attachment_doc. Knowing that, I would either use the attachment API (https://docs.servicenow.com/bundle/jakarta-servicenow-platform/page/integrate/inbound-rest/concept/c...) to post it via web services, or I would script it to just duplicate those records for any of the three attachments needed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2017 07:11 AM
"I would script it to just duplicate those records for any of the three attachments needed" - this is what I was trying to do in the script because it is the same attachment that will be used.
So just to make sure I understand the process you outlined:
1. create a new attachment by attaching a document to a request item
2. Look at the sys_attachment, and sys_attachment_doc to see what records were inserted that would associate the document to the current sys_id of the record that it was attached to
3. create the script that would duplicate the what was done with that attachment to add the same document to new records in the workflow. Using the same sys_id for the document (sys_attachment_doc), but just making new associations in the sys_attachment table using the sys_id of the current record.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2017 07:14 AM
Yeah, I think that would do it. That is what I'd do. The most important piece is the sys_attachment_doc, because that holds the base64 encoding. If you get that right, and the links correct, all should fall into place.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2017 09:52 AM
I was able to use the information you gave me to come to a solution. Thanks to you I now have a better understanding of how attachments are handled in the background. Thanks!!!