Copy Attachment from SC Task to RITM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-22-2024 06:26 AM
Hi ,
How do Copy Attachments from SC tasks to RITM (may be 1 or 2 or 3 tasks exists for all the tasks).?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-22-2024 06:48 AM
Hello @raj99918 ,
You can use a Business rule onBefore for this applied on sc_task table and then use the function GlideSysAttachment.copy (https://docs.servicenow.com/bundle/washingtondc-api-reference/page/app-store/dev_portal/API_referenc...). Your BR should be something similar as follows:
/*Table - sc_task
When to Run - Before Update
Condition - Send Attachments to True
Scripts - */
(function executeRule(current, previous /*null when async*/ ) {
// Add your code here{
GlideSysAttachment.copy('sc_task', current.getUniqueValue(), 'sc_req_item', current.parent.getUniqueValue());
})(current, previous);
There's also an action into flow designer called 'Cpy attachment'. You can use flow designer for this instead BR, as you prefer.
☆ Community Rising Star 22, 23 & 24 ☆
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-22-2024 07:01 AM
Hi @raj99918 ,
You can write below BR ,
Table: sys_attachment
condition : after Insert
(function executeRule(current, previous /*null when async*/ ) {
var taskRec = new GlideRecord('sc_task');
taskRec.addQuery('sys_id', current.table_sys_id);
taskRec.query();
if (taskRec.next()) {
var attachment = new GlideRecord('sys_attachment');
attachment.addQuery('table_sys_id', current.table_sys_id);
attachment.orderByDesc('sys_created_on');
attachment.query();
if (attachment.next()) {
var ritmRec = new GlideRecord('sc_req_item');
ritmRec.addQuery('sys_id', taskRec.request_item);
ritmRec.query();
if (ritmRec.next()) {
var gsa = new GlideSysAttachment();
gsa.writeContentStream(
ritmRec,
attachment.file_name,
attachment.content_type,
gsa.getContentStream(attachment.sys_id));
}
}
}
})(current, previous);
Please mark this comment as Correct Answer/Helpful if it helped you.
Regards,
Swathi Sarang