Attachment only in Catalog Task

AbhirupD
Tera Contributor

I have created a flow which is getting triggered when Catalog Item has been submitted. In that flow I am creating a Catalog Task after approval is done. I want to attach a file only to that Catalog Task. I am created a new Action for that and using below script in Script Step:

 

(function execute(inputs, outputs) {
    var attach = new GlideSysAttachment();
    var rec = new GlideRecord(inputs.task_table);
    rec.get(inputs.taskSysID);
    var fileName = inputs.fileName;
    var contentType = "application/json";
    var content = inputs.jsonContent;
    var agr = attach.write(rec, fileName, contentType, content);
    outputs.attachment_sys_id = agr;
})(inputs, outputs);
 
But, file has been attached to both Catalog Task & Catalog Item. Please help.
1 ACCEPTED SOLUTION

Uncle Rob
Kilo Patron

Take a normal sc_task and attach something to it manually.
Does the RITM get it too?
Then you've got some other code running counter to your solution

View solution in original post

6 REPLIES 6

Uncle Rob
Kilo Patron

That shouldn't be OOB behavior so there's two possibilities.
1)  It only LOOKS like the attachment is in two places.  I've seen lots of people custom related lists to the RITM record to see all attachments for child sc_tasks.
2)  Some custom solution is in place that copies attachment from sc_task to RITM.

Ankur Bawiskar
Tera Patron
Tera Patron

@AbhirupD 

from where are you picking the file?

Is it attached to the catalog item during submission and the same file you want to be copied to catalog task?

You didn't share your flow action is accepting what inputs etc

share some screenshots.

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

AbhirupD
Tera Contributor

I am creating a JSON file using JsonBuilderStep and passing the Output of that to the next step as Scripts to attach the file back to the Catalogue:

 

(function execute(inputs, outputs) {
    var attach = new GlideSysAttachment();
    var rec = new GlideRecord(inputs.task_table);
    rec.get(inputs.taskSysID);
    var fileName = inputs.fileName;
    var contentType = "application/json";
    var content = inputs.jsonContent;
    var agr = attach.write(rec, fileName, contentType, content);
    outputs.attachment_sys_id = agr;
})(inputs, outputs);
 
But, I want to attach the same only the Catalog Task but it seems generic by design that it would always be added in RITM as well. 
 
If so, I have tried to hide the attachment using Catalog Client Script but it is only hiding to add attachment manually but whichever is getting added back via script those are still visible. 
 
function onLoad() {
if (!g_user.hasRole('admin')) { // Adjust the role as needed
g_form.disableAttachments();
var attachmentIcon = document.getElementById('header_attachment');
if (attachmentIcon) {
attachmentIcon.style.display = 'none';
}
}
}

AbhirupD
Tera Contributor

I have created a Action where JsonBuilder Step is creating the JSON file and then same is getting passed to next Script step to attach back the same to Catalog Task. Script Used:

 

(function execute(inputs, outputs) {
    var attach = new GlideSysAttachment();
    var rec = new GlideRecord(inputs.task_table);
    rec.get(inputs.taskSysID);
    var fileName = inputs.fileName;
    var contentType = "application/json";
    var content = inputs.jsonContent;
    var agr = attach.write(rec, fileName, contentType, content);
    outputs.attachment_sys_id = agr;
})(inputs, outputs);
 
But, same is getting attached to RITM as well. If that is generic by design. Then it is also okay to hide the attachments from RITM. I have tried the same with Catalog Client Script :
 
function onLoad() {
if (!g_user.hasRole('admin')) { // Adjust the role as needed
g_form.disableAttachments();
var attachmentIcon = document.getElementById('header_attachment');
if (attachmentIcon) {
attachmentIcon.style.display = 'none';
}
}
}
 
But, it is hiding Attachment clip not the file attached back from the workflow.