Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to get the attachment count in form?

Harendra3
Kilo Explorer

I am unable to get the count of number of attachments inserted in the form.Here i write a business rule in "sys_attachment" table.Can anyone help me to sort out this problem? 

2 REPLIES 2

Mark Stanger
Giga Sage

I'm not sure what you're trying to do exactly, but if you're trying to get a count of attachments associated to an incident or something this type of script would work in a 'before' business rule.

// Query attachments associated to this record
var att = new GlideRecord('sys_attachment');
att.addQuery('table_sys_id', current.sys_id);
att.query();
current.u_attach_number = att.getRowCount();

Pranay Tiwari
Kilo Guru

Hi,

you need to write before(insert & update) BR in Incident table for that.

and in script section use below code.

 var gr= new GlideRecord("sys_attachment");
 gr.addQuery("table_sys_id",current.sys_id);
 gr.query();

current.u_attach_number=gr.getRowCount();

 

Mark correct or helpful if it helps you.

 

Warm Regards,

Pranay Tiwari

| www.DxSherpa.com | pranay.tiwari@dxsherpa.com |