Business Unit table

John160
Giga Contributor

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

1 ACCEPTED SOLUTION

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

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

View solution in original post

14 REPLIES 14

Akshay H Mulky
Kilo Guru

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

Thanks Akshay , will check this and update 

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

Ankur Bawiskar
Tera Patron
Tera Patron

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

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