Populate Department based on business unit

Rahil Mirza
Tera Contributor

If a business unit is selected only the departments related to that business unit should be visible in the department reference field, both business unit and department fields are reference type fields, I have written a script include for the advanced reference qualifier, but it is not working 

Script Include

Name: PopulateDepartment
Accessible from: All application scopes
Client callable: No
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
var PopulateDepartment = Class.create();
PopulateDepartment.prototype = {
    initialize: function() {},

    getDepartment: function(businessUnitId) {
        var departmentList = [];
        if (businessUnitId) {
            var gr = new GlideRecord('cmn_department'); 
            gr.addQuery('business_unit', businessUnitId);
            gr.addQuery('u_active', true);
            gr.query();
            while (gr.next()) {
                departmentList.push(gr.sys_id.toString());
            }
        }
        return departmentList.join(',');
    },

    type: 'PopulateDepartment'
};
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Reference Qualifier
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
javascript:new PopulateDepartment().getDepartment(current.u_sbu_ssu) + '^u_active!=false';

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 ACCEPTED SOLUTION

Brad Bowman
Kilo Patron
Kilo Patron

Change your return line to

 

 return 'sys_idIN' + departmentList.join(',');

 

and you don't really need the concatenated part on the Reference Qualifier, since your GlideRecord includes that.  

 

You could also do this without a Script Include by using a Reference Qualifier that looks more like this:

javascript: 'u_active!=false^business_unit=' + current.u_sbu_ssu;

 

View solution in original post

5 REPLIES 5

Yaramala
Tera Contributor

Hello @Rahil Mirza 

 

You can simply use : javascript: 'business_unitIN' + current.u_sbu_ssu + '^u_active=true'; instead of using script include


If this addresses your question, please mark this response as Accepted Solution and/or give it a Kudos if you find it helpful.

Thank you!