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
Kilo Patron
Kilo 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;

}

 


Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP

View solution in original post

6 REPLIES 6

Musab Rasheed
Tera Sage
Tera Sage

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);


}

Please hit like and mark my response as correct if that helps
Regards,
Musab

Voona Rohila
Kilo Patron
Kilo 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;

}

 


Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP

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.


Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP