Script to rename attachments

Michael Lee1
Tera Expert

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!

4 REPLIES 4

Deepak Ingale1
Mega Sage

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.


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.


Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

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.


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.