How to check if a Case task has attachments

Nishant16
Tera Expert

I have a Display business rule to flag the checkbox "u_has_attachments" on Case task table to check if the record has attachments, but this is not working in Customer service scope and getting an error 
"Function hasAttachments is not allowed in scope sn_customerservice"

find_real_file.png

1 ACCEPTED SOLUTION

Voona Rohila
Tera Patron

Hi Nishant

You can Query the attachment table and get the count of attachments 

var gr= new GlideRecord('sys_attachment');
gr.addQuery('table_sys_id',current.getValue('sys_id'));
gr.query();
if(gr.hasNext()){
current.u_has_attachments = true;
}
else
{
current.u_has_attachments = false;

}

 

View solution in original post

6 REPLIES 6

Musab Rasheed
Kilo Patron

Hi Nishant,

There is another script which you can try in case below doesn't work. Write before BR again.

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




  var att = new GlideAggregate('sys_attachment');


  att.addAggregate('COUNT');


  att.addQuery('table_name', current.getTableName());


  att.addQuery('table_sys_id', current.sys_id);


  att.query();


  var count = 0;




  if (att.next()) {


  count = att.getAggregate('COUNT');


  if (count<1) {


  gs.addInfoMessage("Please attach Attachment");


  current.setAbortAction(true);


  }


  }




})(current, previous);

Murthy Ch
Giga Sage

Hi,

hasAttachments will only work in Global scope. For custom application please use the code as others suggested.

 

Thanks,

Murthy