- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-31-2020 10:40 PM
Hello all ,
I have to filter the values showing in a list type field which is referring to Business Unit table. I don't want to show those values which are parent to any other BU. It means if a BU has a child then only the child BU should be available and not the parent one
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2020 07:46 AM
Hi,
Something like this
Script Include:
var CheckRecords = Class.create();
CheckRecords.prototype = {
initialize: function() {
},
getRecords: function(){
var arr = [];
var gr = new GlideRecord("bu table"); // use valid table name here
gr.query();
while(gr.next()) {
var gr1 = new GlideRecord("bu table"); // use valid table name here
gr1.addQuery("parent", gr.sys_id); // use valid parent field here
gr1.query();
if (!gr1.next()) {
arr.push(gr.sys_id.toString());
}
}
return arr.toString();
},
type: 'CheckRecords'
};
How to call in reference qualifier
javascript: 'sys_idIN' + new CheckRecords().getRecords();
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
10-31-2020 10:43 PM
Hi,
Similar question was asked previously:
You can create a Integer field called childCount, and run below background script:
var bu = new GlideRecord('business_unit');
bu.addEncodedQuery('parentISNOTEMPTY');
bu.query();
while(bu.next()){
var parentBU = bu.parent.getRefRecord();
gs.print("parent"+parentBU.number);
parentBU.u_childcount = parseInt(parentBU.u_childcount) + 1;
gs.print(bu.number);
parentBU.update();
}
In list view, you can filter by :
childCount --- is ----> 0
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2020 06:26 AM
Thanks Akshay , will check this and update
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2020 06:52 AM
Hi Akshay ,
Yeah I've been through this solution. I don't want to create a new field unless it's part of requirement or necessary
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-31-2020 10:52 PM
Hi John,
Can you explain the list field is on which table?
How are parent and child BUs related to each other? any field such as parent etc on the BU table
So basically you don't want to show any BU which has a child in it?
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader