How to copy attachment from RITM TO sc_task in inbound email action?

Aryan
Tera Contributor

Hi All,

 

We have an inbound email action that is on RITM(sc_req_item) ,

 

1. So, when we send email to ABC@example.com with attachments.

2. The inbound email action will trigger and created a REQ, RITM & Sc_task record.

3. In RITM record it will attach all the attachment OOTB, but our requirement is to be attached those attachment in the sc_task record also.

 

Can anyone help me on this?

8 REPLIES 8

Runjay Patel
Giga Sage

Hi @Aryan ,

Write business rule on sc task table and Try below code.

(function executeRule(current, previous /*null when async*/) {
    if (current.request_item) {
        var ritmSysId= current.request_item.toString();
       
        var attachmentGR = new GlideRecord('sys_attachment');
        attachmentGR.addQuery('table_sys_id', ritmSysId);
        attachmentGR.query();
        var attachmentCount = attachmentGR.getRowCount();
     
        if (attachmentCount > 0) {
            while (attachmentGR.next()) {
                GlideSysAttachment.copy('sc_req_item', ritmSysId, 'sc_task', current.sys_id);
            }
        }
    }
})(current, previous);

 

-------------------------------------------------------------------------

If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.


Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay

-------------------------------------------------------------------------

Hi @Runjay Patel ,

 

I tried this BR is not working.

Hi @Aryan ,

 

I have checked its working.

RunjayPatel_0-1732622427576.png

Do not change anything just paste the code it will work

 

Share your business rule screenshot if still not working.

 

-------------------------------------------------------------------------

If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.


Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay

-------------------------------------------------------------------------

 

Hi @Runjay Patel ,

 

I am creating RITM and Sc_task via inbound email action, and in RITM the attachment is coming from the email. I just want to copy that attachment to sc_task.