Can a file be attached to a task on creation - using a script?

Abilash Vangara
Mega Expert

Hello,

 

I have a requirement where a file needs to be attached to a catalog task(created using a workflow) all the time of its creation.

I tried attaching the file to one of the incident and pulling it from there, as this is not a feasible idea because the incidents can be archived when the count increases at some point of time and ultimately loosing the attachment too...is there any better way of achieving this?

 

Any ideas would greatly be appreciated....!

 

 

Thanks in Advance,

Abilash

11 REPLIES 11

Anurag Tripathi
Mega Patron
Mega Patron

Write a before insert BR on the table where you want to implement this functionality.



Manually attach the Template to any existing ticket on Service Now.



In the BR use this functionality to copy the Attachment to the new inserted Ticket.


code:


Packages.com.glide.ui.SysAttachment.copy(this.current.table_name, this.current.table_sys_id, taskGlide.top_task.sys_class_name, taskGlide.top_task.sys_id);


Parameters : 'sourcetable', 'sys_id', 'destinationtable', 'sys_id'




By this way you will copy the existing attachment template to all newly created ticket.



Thanks,


Anurag


-Anurag

If you're on Calgary or newer, you'll need to use the newer script object calls instead of the older package calls. In this case it would be the following:



GlideSysAttachment.copy('sourcetable', 'sys_id', 'destinationtable', 'sys_id');



Copy Attachments from Record to Record - ServiceNow Wiki


Hi Anurag,



Can you help me with this Attachments Copy



Thank you.


Abilash Vangara
Mega Expert

Thanks Anurag and Brad for your prompt replies, I already achieved this using "Copy attachments from Record to Record", I attached the file to an existing incident ticket and copied over to the task....



Also I tried attaching the file to a record of a user defined table(e.g.   which is not visible to any users except admins(so that no end user or ITIL user alter it) but this method didn't work perhaps as the table is not accessible to ITIL users the file is not copied over. So can you help me to find any such table record where I can attach the file and copy over to the task or any way I can attach it in the BR directly???.... I see an attachment table but wonder if it works?



Thanks in Advance,


Abilash