Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

will the attachment be carried to the Catalog task whatever I attached in the catalog item?

divyadhanda
Tera Contributor

I have an attachment and i have added via catalog item view and it s available in the RITM after creating a request, but it s not present in the Sctask. How can i bring in Sctask ?

2 ACCEPTED SOLUTIONS

Ankur Bawiskar
Tera Patron
Tera Patron

@divyadhanda 

you can use after insert business rule on sc_task to copy attachment from RITM to SC Task

(function executeRule(current, previous /*null when async*/ ) {

    new GlideSysAttachment().copy('sc_req_item', current.request_item, 'sc_task', current.sys_id);

})(current, previous);

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

Sarthak Kashyap
Mega Sage

Hi @divyadhanda ,

 

I tried your problem in my PDI and it is working fine for me please create one OnBefore Business Rule which works when sc_task inserted and add below script 

 

(function executeRule(current, previous /*null when async*/) {

	// Add your code here
	var ritmId = current.request_item;

    var att = new GlideRecord('sys_attachment');
    att.addQuery('table_sys_id', ritmId);
    att.addQuery('table_name', 'sc_req_item');
    att.query();

    while (att.next()) {
        GlideSysAttachment.copy('sc_req_item', ritmId, 'sc_task', current.sys_id);
    }

})(current, previous);

 

SarthakKashyap_0-1761917384985.png

SarthakKashyap_1-1761917403354.png

 

Result: 

RITM have attachment

SarthakKashyap_2-1761917428831.png

Same attachment got attached to sc_task

SarthakKashyap_3-1761917460607.png

 

Please mark my answer correct and helpful if this works for you

Thanks and Regards,

Sarthak

 

 

 

View solution in original post

13 REPLIES 13

@Sarthak Kashyap 

Could you please help with your code how many files will be copied?

Example: if RITM has 10 files then with your code using GlideRecord how many files will be there on catalog task?

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Before Insert rule, right? I tried this solution with Before BR, and it works. Thanks a lot for the solution.

@divyadhanda ,

 

Can you please mark solution correct, it will helps others as well.

 

Thanks,

Sarthak

gracemiller84
Giga Contributor

Attachments added via a catalog item are linked to the RITM by default and do not automatically propagate to the SCTask. To make them available on the SCTask, you can modify the catalog item’s workflow or business rule to copy attachments from the RITM to the SCTask when tasks are created, typically using a script in a ‘on task insert’ business rule or in the workflow’s task creation activity. This ensures attachments are accessible on both the RITM and its associated tasks.