- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-26-2016 06:05 AM
How can we check if the record has an attachment in list view. As now we have to open every record to see if the record has an attachment.
so want to know if record has an attachment from list view itself, how we can achieve this.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-26-2016 08:10 AM
Another way that is possible is using the hasAttachments() on the sys_ui_style table for the record. For instance if I wanted an icon or color change to indicate that the record has an attachment in the list view I could setup a style like so:
And if the record has an attachment it will display like below (I didn't have a paperclip icon 😞
(Notice the little yellow document icon)
I know, aesthetically it's not all that pretty. But it's an option. Perhaps maybe if the field were just an empty field and then this style placed on that field it may look better.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-27-2021 11:37 AM
I was able to run this by running an adjusted code through the background script feature. The code had to be adjusted slightly since i cant use current in a background script, as no record is selected, you have to query the table and iterate through it.. this is the adjusted code, it can be ran on any table by adjusting the word incident on first line to the table with the u_attachments and u_attachment_count fields.
Once nice thing I found with the business rule that's applied on the attachment table, is that it will work no matter which table gets the attachment inserted. as long as those two fields are present and the style is setup for that those fields in that table to show the icon. I've implemented this on 3 different tables so far and plan on doing more.
var gr = new GlideRecord("incident");
// gr.setLimit(5); // this line lets you test for a set number of records before running on the whole table, its currently commented out so it will run on everything, remove the comment and set the number of records you want to test on, currently set to 5 records.
gr.query();
while(gr.next()) {
checkAttachment(gr); //This line is where the existing business rule started, for running in background it’s been modified to use new glide record instead of current. (gr)
}
function checkAttachment(gr){
var attachCount = new GlideAggregate('sys_attachment');
attachCount.addQuery('table_sys_id', gr.sys_id);
attachCount.addQUery('table_name', gr.sys_class_name);
attachCount.addAggregate('COUNT');
attachCount.query();
var numAttachments = 0;
if (attachCount.next()){
numAttachments = attachCount.getAggregate("COUNT");
setAttachmentNum(numAttachments,gr);
}
else{
setAttachmentNum(numAttachments,gr);
}
}
function setAttachmentNum(num,gr){
var task = new GlideRecord(gr.sys_class_name);
task.get(gr.sys_id);
if(task.isValidRecord()){
if(num > 0) {
task.u_attachments = "true";
task.u_attachment_count = num;
}
else {
task.u_attachments = "false";
task.u_attachment_count = "";
}
task.autoSysFields(false); //Don't set the last UpdateTime or the Simultaneous Update
task.setWorkflow(false); //Don't allow other business rules to run otherwise multiple notices will appear
task.update();
}
}