- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-14-2014 10:55 AM
I've seen a couple requests to add a date/time stamp to the attachment of a Scheduled Report. Capa JC shows us how to add this to the email's subject in this post (When configuring a Scheduled), but doing it on an attachment is still not possible. Until now.
A nice little workaround with a Business Rule on the Email table is all you need. When you configure your Scheduled Report, add "~!~rename_attachment~!~" as a prefix to the Subject to act as a trigger for the Business Rule (e.g. "~!~rename_attachment~!~Active Change Requests").
Next, add the following Business Rule:
Name: Custom - Rename Scheduled Report Attachments Table: Email [sys_email] When: before Insert: checked Condition: current.subject.indexOf("~!~rename_attachment~!~") > -1 && current.hasAttachments() Script: (function(){ var splitter = "~x~y~z"; current.subject = current.subject.replace("~!~rename_attachment~!~", ""); var gr = new GlideRecord("sys_attachment"); gr.addQuery("table_name", "sys_email"); gr.addQuery("table_sys_id", current.getValue("sys_id")); gr.query(); while (gr.next()) { var fileName = gr.getValue("file_name"); var parts = fileName.split("."); var dateCreated = splitter + gr.getValue("sys_created_on"); parts.splice(-1, 0, dateCreated); fileName = parts.join(".").replace("." + splitter, "-"); gr.file_name = fileName; gr.update(); } })();
The Business Rule queries the attachments, grabs each file name, splits it apart, inserts the created date, joins it back together and then finally updates the record with the new file name.
Simple
Solved! Go to Solution.
- 11,292 Views
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-20-2018 06:08 AM
Just setting this answer as correct as the actual thread was not meant as a question and it cannot be changed because it came from the original Community site.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-14-2014 12:28 PM
Thank you very much. I have tested this successfully! - Cort
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-24-2015 07:38 AM
Thanks for sharing! I just tried running this and it seems to work, but I have a question on the title, what does the "144014" represent?
Active Task-2015-03-24 144014
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-14-2015 07:09 PM
I'm sorry, I just noticed your post now. Where are you getting the "144014" string? In the filename of the attachment?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-15-2015 12:05 PM
Hi Jim,
yes it was on the file name of the attachment.