- 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 03:09 AM
Hi @Samiksha2 ,
It was due to 'current.table_sys_id' as you have created the UI action on sctask table 'table_sys_id' field does not exist over there(it exist in attachment table), hence i just used 'current.sys_id' because the aim was just to get the sys id of the task record.
Thanks,
Danish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2023 03:32 AM
Hi @Danish Bhairag2 ,
It is working fine in backend but in workspace button is not showing. I checked the Workspace option also.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2023 04:09 AM
Hi @Danish Bhairag2 ,
Its working now. I have created UI Form Actions.
Thanks @Hemanth M1 and @Danish Bhairag2 once again.