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,

Try this before BR

var attachRec = new GlideRecord("sys_attachment");


attachRec.addQuery("table_name", current.getTableName());


attachRec.addQuery("table_sys_id", current.sys_id);


attachRec.query();


if (!attachRec.next()) {


      gs.addErrorMessage("You must attach a complete import template before submitting.");


      current.setAbortAction(true);


}

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;

}

 

Hi Rohila,

This only works when i update the case task, if i just upload an attachment and do not update the task, the check box remains false

You should write a BR on attachment table and make the field true/false when user inserts/deletes the attachment.

Check the solution from Ian Mildon in below post

https://community.servicenow.com/community?id=community_question&sys_id=ac4034041b470c10a59033f2cd4b...

 

You can try and let us know if you're stuck.