Script to rename attachments
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-04-2018 09:46 AM
We're exploring the possibility of using SNow as a document management system. Does anyone know if there's a way to automate renaming a file that's uploaded as an attachment to a form, using javascript or any other method? Specifically, I'd like to add the ticket number generated by SNow to the end of the filename.
Example:
User uploads file 'Deliverable.pdf'
The ticket created is 'DPC100071'
The file uploaded is renamed to 'Deliverable_DPC100071.pdf
The idea is that the document can be traced to a specific record for later reference.
Any ideas are very much welcomed!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-04-2018 09:52 AM
Hi Michael,
Attachments are linked to RECORDs via table_sys_id and table_name fields on sys_attachment table in ServiceNow. If only tracing is the requirement, we can have it fulfilled by using it OOB way.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-04-2018 10:15 AM
Thank you for your help Deepak,
The "tracing" that is needed is not necessarily in the system. It's so that once the document has been completed and delivered if a user has an issue with their document, they can reference the number on their document. The document production department can then easily search in the system by the number and reference any communication that took place regarding that document.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-04-2018 09:53 AM
Hello Michael,
As the attachments are stored in "sys_attachment" table, you can write an AFTER business rule on the table where documents will be uploaded and GlideRecord the exact sys attachment record, update the file name.
Please let me know if you have any questions.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-04-2018 10:11 AM
Thank you Pradeep! I'm new to this type of thing and still don't quite understand it completely.
The business rule will run on the table that will be created for our application after the new record has been inserted. Then using GlideRecord, I will reference the attachment on the sys_attachment table and write a script to rename it?
I appreciate your patience.