Copy attachments from one SCTask to antoher

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-02-2023 02:18 AM
hi Guys,
how we can copy attachments from one SC Tasks to another SCTasks.
for example: one request having multiple SCTasks, I 'm not going attach the attachments in Request.
I want to attach the attachment in any SCTAsk, that attachment should be copied to antoher tasks..
please help me.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-02-2023 02:28 AM
@Kishor Mudhili Wrie a business rule on sys_attachment table
Add below code in business rule
(function executeRule(current, previous /*null when async*/ ) {
var currentScTask = new GlideRecord("sc_task");
if (currentScTask.get(current.table_sys_id.toString())) {
var catTask = new GlideRecord("sc_task");
catTask.addQuery("sys_id!=" + current.table_sys_id.toString());
catTask.addQuery("request=" + currentScTask.request.toString());
catTask.query();
while (catTask.next()) {
GlideSysAttachment().copy("sc_task", currentScTask.sys_id.toString(), "sc_task", catTask.sys_id.toString());
}
}
})(current, previous);
Please mark as correct answer if this solves your issue.
ServiceNow Community Rising Star, Class of 2023

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-02-2023 03:49 AM
hello Jaheer,
how did you get this ?, wihout this i have wrintten the code on SCTask table but not working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-02-2023 04:03 AM
@Kishor Mudhili you need to add business rule on sys_attachment table not on sc_task.
Please create it and check.
Please mark as correct answer if this solves your issue
ServiceNow Community Rising Star, Class of 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-02-2023 04:47 AM
@Kishor Mudhili I have updated the code.
Create after insert business rule on sys_attachment table and below code
ServiceNow Community Rising Star, Class of 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-02-2023 04:13 AM
Won't this just run in loop if you have more than one sc_task?
Best regards,
Sebastian Laursen