The CreatorCon Call for Content is officially open! Get started here.

Catalog Item Attachments are all showing up on SCTASK after Vancouver Upgrade

Zubair Alam
Tera Contributor

Please guide on why all attachments attached to a catalog items are showing under SCTASK related list "attachment" tab, when a user is only submitting just one of those attachments. 
This issue surfaced after Vancouver upgrade. 
Please guide if I can create a Business Rule to allow only the user submitted attachment to show on the SCATSK rather than all the attachments attached to catalog item. 
Any help is appreciated. Thanks. 

5 REPLIES 5

Hi Jaspal,

                 Looked as you suggested, This relationship script applies to the "task" table and queries from sys_attachment. 

(function refineQuery(current, parent) {

    try{


       var itemList = getItemList();


       //Get attachments for all of the above


       current.addQuery('table_sys_idIN' + itemList);


}


catch(e){


       gs.log("Error(" + e.lineNumber + "): " + e, "CONSOLIDATED ATTACHMENTS");


}




function getItemList(){


       var arrItems=[],references=[],relTasks=[],relEmails=[];


       relTasks=[parent.sys_id];


   //Get References


       references = getReferences(parent);


   //Get Emails


       var instanceList = relTasks.concat(references);      


       relEmails = getRelatedEmails(instanceList.join());


       arrItems = instanceList.concat(relEmails);


       return arrItems.join(); //Return as a CSV list


}



function getReferences(parent){


   //Get referenced record_ids


       var refFields = parent.getFields();


       var itemListRefs = [];


       for (var i=0; i<refFields.size(); i++) {


               var field = refFields.get(i);


               var ed = field.getED();


               if(field.getED().getInternalType() == 'reference' && field.hasValue()){


                               itemListRefs.push(field.toString());


               }


       }


       return itemListRefs;


}



function getRelatedEmails(instanceList){


       var strItems = '';


       var grRelEmail = new GlideRecord('sys_email');


       grRelEmail.addQuery('instanceIN' + instanceList);


       grRelEmail.query();


       while(grRelEmail.next()){


               strItems += grRelEmail.sys_id + ',';


       }      


       return strItems.split(',');


}



})(current, parent);