Attachment Count in Change Request table for Reports

Hari S1
Tera Contributor

Hi,

 

We are creating a Report on the Change Request table and would like to display the number/count of attachments attached to each change record.

 

Can someone please assist me with this?

4 REPLIES 4

manjusha_
Kilo Sage

@Hari S1 

 

You need to create a field displaying count of attachment and to update that field you need to write the logic using business rule

Check with your customer if they are ok to have a new field on form

 

If my answer solved your issue, please mark my answer as Correct & 👍Helpful based on the Impact

 

Thanks,

Manjusha 

Hi @manjusha_ ,

 

Yes, cutomer agreed to create new field. 

@Hari S1 

 

Use below code to update count field on change form(count field you need to create on the form ) 

 

 

var grAtt= new GlideAggregate('sys_attachment');
var count ='';

grAtt.addQuery('table_name','change_request');
grAtt.addQuery('table_sys_id',current.sys_id);
grAtt.addAggregate('COUNT');
grAtt.query();
while(grAtt.next()){
count =grAtt.getAggregate('COUNT');
}
current.attachmentCount = count;// replace AttachmentCount with the count field name which you created on your change form 

 

 

 If my answer solved your issue, please mark my answer as Correct & 👍Helpful based on the Impact

Thanks,

Manjusha Bangale

S Goutham
Tera Guru

Hey @Hari S1 :

You could report on the sys_attachment table, however, it is not permitted  OOB. If you wish to report on the Attachments table, you must add the sys_attachment table to the permitted tables property [glide.ui.permitted_tables]. 

 

The best approach is to have a custom field option as a counter on the table and BR on the attachment table to run on insert or delete to update the counter 

I hope this solves your issue
Mark this as Helpful / Accept the Solution if this clears your issue