- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2023 01:36 AM
Hi All,
I have a requirement to copy attachment form sctask to ritm but not all attachments. So for that we need toadd a button in the sctask. When a fulfiller add the attachment and click on the button the uploaded(recent) attachment should be copied to RITM.
Please help.
Thanks,
Samiksha
Solved! Go to Solution.
- Labels:
-
Service Catalog

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2023 02:25 AM
Hi @Samiksha2 ,
Refer here: https://www.servicenow.com/community/developer-forum/copy-newest-attachment-only-from-task-to-ritm/m...
Thank you,
Hemanth
Certified Technical Architect (CTA), ServiceNow MVP 2024, 2025
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2023 02:59 AM
Hi @Samiksha2 ,
Copy past the exact code in your UI action script section, which you will be creating on sc_task table:
var taskRec = new GlideRecord('sc_task');
taskRec.addQuery('sys_id', current.sys_id);
taskRec.query();
if (taskRec.next()) {
var attachment = new GlideRecord('sys_attachment');
attachment.addQuery('table_sys_id', current.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));
}
}
}
Please mark @Hemanth M1 answers correct if it helps u resolve your query,
Thanks,
Danish

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2023 02:25 AM
Hi @Samiksha2 ,
Refer here: https://www.servicenow.com/community/developer-forum/copy-newest-attachment-only-from-task-to-ritm/m...
Thank you,
Hemanth
Certified Technical Architect (CTA), ServiceNow MVP 2024, 2025
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2023 02:29 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2023 02:59 AM
Hi @Samiksha2 ,
Copy past the exact code in your UI action script section, which you will be creating on sc_task table:
var taskRec = new GlideRecord('sc_task');
taskRec.addQuery('sys_id', current.sys_id);
taskRec.query();
if (taskRec.next()) {
var attachment = new GlideRecord('sys_attachment');
attachment.addQuery('table_sys_id', current.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));
}
}
}
Please mark @Hemanth M1 answers correct if it helps u resolve your query,
Thanks,
Danish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2023 03:03 AM
Hi @Danish Bhairag2 ,
I added the code in UI action dont know why that was not running. I copied your code its working.
Thanks.😊