The CreatorCon Call for Content is officially open! Get started here.

Attachment count

Riaz3
Giga Expert

Hi,

Is it possible in any way to report on the number of attachments on a form?

Ideally, in a List view i would like a field to say Attachments, and then have the number of attachments of that record or even a true of false.

Thanks.

1 ACCEPTED SOLUTION

I just spotted one more thing that you'll need to change this to an After, which I found worked better.

I also set the Condition line on the Advanced tab to be (so set this for the correct table on each of your Business Rules): 

current.table_name == "ast_contract"
 
Which will provide the values for the queries. And as I already mentioned, the result was being fed to the "u_attachments" integer field on the Contract record. So you would set the 5th line in the "setAttachmentNum(num)" function to:
task.u_attachment_count = num;
 

View solution in original post

11 REPLIES 11

A business rule requires that the data it is referencing is in a database, so until the new record is saved, the scripted functions will not work. And while a "display" business rule will behave similar to an onLoad client script, it would still be looking for entries in a table/database, which requires the data is saved first.

What you are wanting to do is a client side function and will require the use of a Client Script.

Got this part working by creating a new Business Rule but using the actual table (not the attachments table). Still running it after, gave it a lower order number and only using it when insert. Script used as follow:

var count = new GlideRecord('sys_attachment');
    count.addQuery('table_sys_id',current.table_sys_id);
    count.query();

gs.info('count' + count.getRowCount());
    current.u_attachments = count.getRowCount(); //match to integer field name
    current.autoSysFields(false); //Don't set the lastUpdatedTime or the Simultaneous Update Alert will likely get triggered
    current.setWorkflow(false); //Don't allow other business rules to run, otherwise multiple notifications will likely be sent
    task.update();

 

This way the attachments count will show when a new record is inserted with X numbers of attachments. The other business rule(shown in previous reply) will continue to count when record is updated.

Again thanks for the assistance.