- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā04-12-2022 12:01 AM
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"
Solved! Go to Solution.
- Labels:
-
Customer Service Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā04-12-2022 12:09 AM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā04-12-2022 12:14 AM
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);
Regards,
Musab
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā04-12-2022 12:47 AM
Hi,
hasAttachments will only work in Global scope. For custom application please use the code as others suggested.
Thanks,
Murthy
Murthy