Get row count of related records

Priya75
Tera Contributor

Hi All, 

I have a field on the form as test. i want to populate this field on the basis of a related list, so i have a related list of business service which shows the records from cbdb_ci_service tables.i want to count of services related to that particular task and update that field. 

11 REPLIES 11

Hi Priya,

So since you want field to be updated based on service is added/updated or deleted then BR should be on cmdb_ci_service table

There must be some field on cmdb_ci_service which holds certificate information

query with that field and then get the count

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi,

so in cmdb_ci_service table.. the certification is the related list. so we query same way like we query a table?

Hi Priya,

Hope you are doing good.

Let me know if that answered your question.

If so, please mark appropriate response as correct & helpful so that this thread can be closed and others can be benefited by this.

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi Priya,

Hope you are doing good.

Let me know if that answered your question.

If so, please mark appropriate response as correct & helpful so that this thread can be closed and others can be benefited by this.

Regards
Ankur

 

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Sajilal
Mega Sage

Have the field as a calculated field maybe? and query your respective table and get the rowcount.


var categoryCount = 0;
var gr = new GlideAggregate('your table');
gr.addQuery(your query);
gr.addAggregate("COUNT");
gr.query();
while(gr.next()) {
categoryCount = gr.getAggregate("COUNT");
}
return categoryCount;

Please Mark as Correct if this solves your issue and also mark ???? Helpful if it helps resolve your problem.

Thanks,
Saji