We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

UI Action to copy attachment from SCTASK to RITM

Samiksha2
Mega Sage

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

2 ACCEPTED SOLUTIONS

Hemanth M1
Giga Sage

Hi @Samiksha2 ,

 

Refer here: https://www.servicenow.com/community/developer-forum/copy-newest-attachment-only-from-task-to-ritm/m... 

Accept and hit Helpful if it helps.

Thank you,
Hemanth
Certified Technical Architect (CTA), ServiceNow MVP 2024, 2025

View solution in original post

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

View solution in original post

7 REPLIES 7

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

Hi @Danish Bhairag2 ,

 

It is working fine in backend but in workspace button is not showing. I checked the Workspace option also.

Samiksha2_0-1695119555238.png

 

Hi @Danish Bhairag2 ,

Its working now. I have created UI Form Actions. 

 

Thanks @Hemanth M1 and @Danish Bhairag2 once again.