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.

Attachment count!!

coolboy
Mega Expert

Hi on kb_knowledge table i have created a field called attachment counter (this field will be counting the number of attachment to particular article.)
Any idea how to do this.I am thinking of making after isert/update b.Rule.

var att = new GlideRecord("sys_attachment");
att.addQuery("table_name","kb_knowledge");


what else :-)....

11 REPLIES 11

Hi Prerna,,



Try with Business rule on kb_knowledge table with the below code..




var count = new GlideRecord('sys_attachment');


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


count.query();



gs.log('count' + count.getRowCount());



current.u_attachment_count = count.getRowCount();


current.update();



Regards,


Sadasiva



Please mark helpful/ correct based on the impact


Sadasiva Reddy
Giga Guru

Hi,



Try with Business rule on kb_article table with the below code..




var count = new GlideRecord('sys_attachment');


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


count.query();



gs.log('count' + count.getRowCount());



current.u_attachment_count = count.getRowCount();


current.update();



Regards,


Sadasiva



Please mark helpful/ correct based on the impact