Total Number of attachments
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-31-2017 04:41 AM
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-31-2017 04:46 AM
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();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-31-2017 04:47 AM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-31-2017 04:50 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-31-2017 05:17 AM
Hi Manisha,
You have to write an after insert business rule in sys_attachment table by adding the condition as table name as incident.