Filter Assigned To values using reference qualifier and script include

heathers_
Kilo Sage

Hello, I need to filter the Assigned To values based on value of another field. If the condition is not met, I need to display the full list of group members for that specific assignment group. Below is my attempt thus far... any insight or ideas? 

 

Condition: If "u_hr_confidential" = Yes, only display the users with role "sn_hr_core.u_hr_confidential" from assignment_group in assigned_to.

Else, display all users in assignment group.

Reference Qualifier on Assigned To

heathers__0-1712081681777.png

javascript: new sn_hr_core.HrCaseAjaxUtils().getConfidential(current.u_hr_confidential);

 

 

Script Include

 

var HrCaseAjaxUtils = Class.create();
HrCaseAjaxUtils.prototype = {
    initialize: function() {
},
    getConfidential: function(field) {

        var confidential = current.u_hr_confidential;

        if (field == 'Yes') {
			gs.info("HRSD1: " + role);
			gs.info("HRSD2: " + confidential);
            var gr = new GlideRecord('sys_user_grmember');
            gr.addEncodedQuery('user.roles=sn_hr_core.u_hr_confidential');
            gr.query();
            var arr = [];
            while (gr.next()) {
                arr.push(gr.sys_id.toString());
            }
            return 'sys_idIN' + arr.toString();

		}
    },

 

 

1 ACCEPTED SOLUTION

heathers_
Kilo Sage

Using a combination of all recommendations, I have resolved the issue while keeping the script include Client Callable.

var HrCaseAjaxUtils = Class.create();
HrCaseAjaxUtils.prototype = {
    initialize: function() {},

    getConfidential: function(u_hr_confidential) {
        gs.info("HRSD1: " + u_hr_confidential);

        if (u_hr_confidential == 'Yes') {
            gs.info("HRSD2: " + u_hr_confidential);
            var arr = [];
            var gr = new GlideRecord('sys_user_grmember');
			gr.addQuery('group',current.assignment_group); 
            gr.addEncodedQuery('user.roles=sn_hr_core.u_hr_confidential');
            gr.query();
            while (gr.next()) {
                arr.push(gr.user.toString());
            }
            return 'sys_idIN' + arr;


        }
    },

    type: 'HrCaseAjaxUtils'
};

 

View solution in original post

6 REPLIES 6

Appanna M
Tera Guru

Hello @heathers_ ,

 

Okay, Can you try the below once.

 

var HrCaseAjaxUtils = Class.create();
HrCaseAjaxUtils.prototype = {
    initialize: function() {
},
    getConfidential: function(field) {
gs.info("HR Confi:"+field);
        if (field == 'Yes') {
			//gs.info("HRSD1: " + role);
			gs.info("HRSD2: " + field);
            var arr = [];
            var gr = new GlideRecord('sys_user_grmember');
            gr.addEncodedQuery('user.roles=sn_hr_core.u_hr_confidential');
            gr.query();
            while (gr.next()) {
                arr.push(gr.user.toString());
            }
            return 'sys_idIN' + arr;

		}
    },

 

 

Please Mark My Answer as Helpful and Accept as Solution, if you find this article helpful or resolves your issue.

heathers_
Kilo Sage

Using a combination of all recommendations, I have resolved the issue while keeping the script include Client Callable.

var HrCaseAjaxUtils = Class.create();
HrCaseAjaxUtils.prototype = {
    initialize: function() {},

    getConfidential: function(u_hr_confidential) {
        gs.info("HRSD1: " + u_hr_confidential);

        if (u_hr_confidential == 'Yes') {
            gs.info("HRSD2: " + u_hr_confidential);
            var arr = [];
            var gr = new GlideRecord('sys_user_grmember');
			gr.addQuery('group',current.assignment_group); 
            gr.addEncodedQuery('user.roles=sn_hr_core.u_hr_confidential');
            gr.query();
            while (gr.next()) {
                arr.push(gr.user.toString());
            }
            return 'sys_idIN' + arr;


        }
    },

    type: 'HrCaseAjaxUtils'
};