Total Number of attachments

manisha3014
Kilo Contributor

Hi All,

In incident form, i have created a field "total attachment" in that field i want to get total number count of attachment in the form. How to get that one. Anyone please help me.

Thank you in advance.

8 REPLIES 8

Jaspal Singh
Mega Patron
Mega Patron

Hi Manisha,



Try below after update business rule on incident table.



var count = new GlideRecord('sys_attachment');


count.addQuery('table_sys_id',current.sys_id);


count.query();



gs.log('count' + count.getRowCount());   //Prints in logs to check the count.



current.u_attachment_count = count.getRowCount();   // provided u_attachment_count is the field name


current.update();


Khozema Attar1
Tera Guru

Hi Manisha,



You could use something like this in business rule:



Name: Add attachment


Table: sys_attachment


Active: true


Advanced: true


Insert: true


Update: false


When: After


Condition: current.table == 'YOUR_TABLE_NAME'



Script:


var count = -1;


var att = new GlideAggregate('sys_attachment');


att.addQuery('table', current.table);


att.addQuery('table_sys_id', current.table_sys_id);


att.addAggregate('COUNT');


att.query();



if (att.next()) {


      count = att.getAggregate('COUNT');


}



var rec = new GlideRecord(current.table);


rec.get(current.table_sys_id);


var val = parseInt(rec.getValue('u_attachment_count'), 10); // use your count field name here


val++;


rec.u_attachment_count = val;


rec.update();



Thanks,



Mark as helpful/Correct if it helps


Stefan Baldhof1
Kilo Guru

Hi Manisha,



choose "Configure Dictionary" for your custom field, then switch to "Advanced View" and choose "Calculated Value". There you can add the neccessary script logic to return the number of attachments for the current record.



See also the screenshot




calculated _value.png



Regards,


Stefan


vinothkumar
Tera Guru

Hi Manisha,



You have to write an after insert business rule in sys_attachment table by adding the condition as table name as incident.