Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to move attachment from HR case to HR task

abirakundu23
Giga Sage

Hi All,

I have to move attachment from HR case to HR task when HR case status is "work in Progess" . I have write a BR on c HR case table but it is not working any more. could you please look into this ??

GlideSysAttachment.copy("sn_hr_core_global_mobility",current.parent,"sn_hr_core_task", current.sys_id);

 

4 REPLIES 4

Musab Rasheed
Tera Sage

Hello,

This has working code

https://community.servicenow.com/community?id=community_question&sys_id=2cf37c4bdbe7c110770be6be13961962

Regards

Please hit like and mark my response as correct if that helps
Regards,
Musab

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

I would suggest not to copy files as it will increase table size of sys_attachment.

Instead check this blog

"Related Attachments" Related List

If you still require then update your script as this to copy files to all HR Tasks under this HR Case

BR: HR Case Table

Condition: HR case status is "work in Progess"

var gr = new GlideRecord("sn_hr_core_task");
gr.addQuery("parent", current.sys_id);
gr.query();
while (gr.next()) {
	GlideSysAttachment.copy(current.getTableName(),current.sys_id,"sn_hr_core_task", gr.sys_id);
}

regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Hi Ankur,

we have to write this piece of code in which table ?? Please once.

var gr = new GlideRecord("sn_hr_core_task");
gr.addQuery("parent", current.sys_id);
gr.query();
while (gr.next()) {
	GlideSysAttachment.copy(current.getTableName(),current.sys_id,"sn_hr_core_task", gr.sys_id);
}

Hi,

you want files to copy when HR case status is "work in Progess"

So it will be on HR Case table.

I already covered it in my earlier response.

If my response helped please mark it correct and close the thread so that it benefits future readers.

regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader