The CreatorCon Call for Content is officially open! Get started here.

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_ ,

 

Please correct the below line.

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

 

Same type of requirement please follow the Ref URL: https://www.servicenow.com/community/developer-forum/advanced-reference-qualifier-in-servicenow-base...

 

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

 

@Appanna M Thank you for your response. These are not variables. I am creating this directly on the sn_hr_core_case table.

You script include doesnt need to be client

There are several correction you need to make

            var gr = new GlideRecord('sys_user_grmember');
            gr.addQuery('group',current.assignment_group); // You should query the assignment group as well
            gr.addEncodedQuery('user.roles=sn_hr_core.u_hr_confidential');
            gr.query();
            var arr = [];
            while (gr.next()) {
                arr.push(gr.getValue('user')); // You should pass the user sysid here
            }
            return 'sys_idIN' + arr.toString();

 

 


Please mark this response as correct or helpful if it assisted you with your question.

I don't need to make this client callable?

 

Adjusting based on your recommendations and assigned_to is displaying the complete list of group members. Still not seeing the few members with the queried role.