Get row count of related records
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2020 04:30 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2020 04:51 AM
Hi Priya,
When you want to populate that? when any new record gets added in related list?
if yes then you would require BR on that related list table to increment or decrement the count based on insert or delete
Regards
ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2020 04:55 AM
No, when a task is created or updated and a business service is added to that task.i can't have run a business rule on cmdb_ci_service table.i want that count from task table and need to update the field .could you provide some scripting
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2020 05:11 AM
Hi Priya,
So you would require before update BR on the current table.
Sample script below
var gr = new GlideRecord('cmdb_ci_service');
gr.addQuery('task', current.sys_id);
gr.query();
current.<fieldName> = gr.getRowCount();
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2020 05:16 AM
i want it on cert_task table. when a related service is added or updated .
what i have to mention in current.field name.. when it is a table record.
I have a certificate task form, in this the business services(cmdb_ci_services)is the related list record.i have a field on the certificate task form as test. i want to populate this field, for that i want to count all the service record in business service related list.