- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-29-2016 10:23 AM
I have added some related list to my form and I am trying to find out whether that related list has any rows/results on it from UI Action. Is there any easy way to find it programatically?
Solved! Go to Solution.
- Labels:
-
User Interface (UI)

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-29-2016 10:51 AM
If you know the table that the related list is showing records for, and the field it is using to reference the current record, sure. I'll use change_request with a related list of change_task records on it. chage_task.change_request is the field used to create the related list automatically. That is to say that change_request field on the change_task record is the reference to the change_request table.
So if I want a UI action on change_request to tell me how many change_tasks there are...
var count = 0;
var ga = new GlideAggregate('change_task');
ga.addAggregate('COUNT');
ga.addQuery('change_request', current.sys_id);
ga.query();
if (ga.next())
count = ga.getAggregate('COUNT');
gs.addInfoMessage('There are ' + count + ' change tasks on this change request');
action.setRedirectURL(current);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-29-2016 10:51 AM
If you know the table that the related list is showing records for, and the field it is using to reference the current record, sure. I'll use change_request with a related list of change_task records on it. chage_task.change_request is the field used to create the related list automatically. That is to say that change_request field on the change_task record is the reference to the change_request table.
So if I want a UI action on change_request to tell me how many change_tasks there are...
var count = 0;
var ga = new GlideAggregate('change_task');
ga.addAggregate('COUNT');
ga.addQuery('change_request', current.sys_id);
ga.query();
if (ga.next())
count = ga.getAggregate('COUNT');
gs.addInfoMessage('There are ' + count + ' change tasks on this change request');
action.setRedirectURL(current);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-09-2018 12:31 PM
Chuck, is there a way to use (part of) this script to populate a field on the form with the count of the related records? For me it's KBs (m2m_kb_task) related on the Incident form. I'd like to have a count of the KBs in a field called u_kb_count that lives on the Incident Form.
I tried a Client-side, Before Business rule like this, but it did not work:
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var count = 0;
var ga = new GlideAggregate('m2m_kb_task');
ga.addAggregate('COUNT');
ga.addQuery('incident', current.sys_id);
ga.query();
if (ga.next())
count = ga.getAggregate('COUNT');
g_form.setValue('u_kb_count', count);
})(current, previous);
Thanks,
Richelle
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-24-2018 09:25 AM
Hi Richelle
Did you ever get a response on this? Im trying to do a BR count on a m2m related list as well
Steve
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-24-2018 09:40 AM
No, I'm sorry to say I did not find a way to do this. In the end, I just added another field on the incident form requiring the team member who resolves to validate that the knowledge attached was correct, incorrect, needed updating, or wasn't available.
An ugly solution, but it also gives us a way to find knowledge that needs updating, creating or a Service Desk Analyst that need education.
Richelle