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,



My count of attachment is coming as 2383..


Can you please help?


Hi Prerna,



Can you share your code please.


HI Siddartha,


PFB my code . Can u pls help me in getting the attachment count.



find_real_file.png



find_real_file.png


var x = new GlideRecord('kb_knowledge');


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


x.query();


while(x.next())------------------------------------------------------------------- change added here


{


var y = new GlideRecord('sys_attachment');


y.addQuery('table_sys_id',x.sys_id);


y.query();


x.u_attachment_count = y.getRowCount();


x.update();


}



Use while loop above code and check



Please like or Mark correct based on the impact of response.


It's not working.


Ni log came even.


find_real_file.png



find_real_file.png