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

Reference Qualifier

Mark Wood
Tera Contributor

Hello Experts,

I have written the following script to restrict data for the "Assignment Group" field based on the "Assigned To" field. If the "Assigned To" is Fred Luddy, then I want to show all assignments belonging to Fred Luddy. I am calling my script include using an advanced reference qualifier. When I manually pass the sys_id of the user through a background script, I am getting the correct result without any issues. Please guide me on why it's not working.

 

Script Include:

var  BackfillAssignmentGroup_Using_Array = Class.create();
 BackfillAssignmentGroup_Using_Array.prototype = {
    initialize: function() {
    },
getGroups:function(user)
{
	if(!user)
	{
return;

	}
var group=new GlideRecord('sys_user_grmember');
group.addQuery('user',user);
group.query();
var group_Array=[];
while(group.next())
{
group_Array.push(group.getValue('sys_id'));
}
return "sys_idIN"+group_Array.toString();
},
    type: ' BackfillAssignmentGroup_Using_Array'
};

 Advance Reference Qualifier for Assignment group field.

javascript:new BackfillAssignmentGroup_Using_Array().getGroups(current.assigned_to)

 

1 ACCEPTED SOLUTION

Hello @Mark Wood ,

Thank you very much, and I genuinely appreciate your kind words!🤗 & I've implemented your latest suggestions and made the necessary changes. Now, you have two approaches to choose from:

Approach 1: Using Reference Qualifier Only

  • Please find the below reference qualifier code:
javascript: if(current.assigned_to !="")'sys_idIN' + new global.ArrayUtil().convertArray(gs.getUser().getUserByID(current.assigned_to.toString()).getMyGroups()); else'active=true';

AniketChavan_1-1710783600689.png

 

  • Note: While it's often mentioned that using if-else conditions in reference qualifiers might not be considered best practice, I've personally found it effective in many cases. Additionally, I came across an article that also supports this approach. So, feel free to utilize it as needed.

Approach 2: Using Script Include and Reference Qualifier

  • Alternatively, if you prefer to avoid if-else conditions in reference qualifiers, you can utilize a script include. I've created a script include named AssignmentGroupReferenceQualifier with the following code:
var AssignmentGroupReferenceQualifier = Class.create();
AssignmentGroupReferenceQualifier.prototype = {
    initialize: function() {
    },

    getAssignmentGroups: function(assignedTo) {
        if (!assignedTo || assignedTo.nil()) {
            // If Assigned To is empty, return all assignment groups
            return 'active=true';
        } else {
            // If Assigned To is not empty, return groups based on the selected user
            return 'sys_idIN' + new global.ArrayUtil().convertArray(gs.getUser().getUserByID(assignedTo.toString()).getMyGroups());
        }
    },

    type: 'AssignmentGroupReferenceQualifier'
};

AniketChavan_0-1710783497473.png

 

 

  • To use this script include in your reference qualifier, use the following code:
javascript: new AssignmentGroupReferenceQualifier().getAssignmentGroups(current.assigned_to)

 

AniketChavan_2-1710783708821.png


Please let me know if you have any further doubts or concerns so that we can address them accordingly. If everything is clear,

 

Please Mark Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.

 

Thanks & Regards,

Aniket.

 

View solution in original post

11 REPLIES 11

Community Alums
Not applicable

I have written code to call script include function from reference qualifier and values displayed based on the another variable

 

Reference Qualifier: javascript: new global.UserList().getQuestionChoice(current.variables.line_of_business.getDisplayValue());

 

API Name: global.UserList
methodName:  getQuestionChoice
 
Script Include:
var UserList = Class.create();
UserList.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    getQuestionChoice: function(lineOfBussiness) {
        spqtid = '2f22360693858210fc78f15a7bba1098';
        var filterQuery = 'question=' + spqtid;
        var labelgr = new GlideRecord("label");
        labelgr.addQuery("name", 'IN', lineOfBussiness);
        labelgr.query();
        var i = 0;
        var tagfilterQuery = "";
        while (labelgr.next()) {
            if (i > 0) {
                tagfilterQuery = tagfilterQuery + '^OR';
            } else {
                tagfilterQuery = tagfilterQuery + '^';
            }
            tagfilterQuery = tagfilterQuery + 'sys_tags.' + labelgr.sys_id + '=' + labelgr.sys_id;
            i++;
        }
        if (i == 0) {
            return 'sys_idISEMPTY';
        }
        filterQuery = filterQuery + tagfilterQuery;
        gs.log("ramesh-" + lineOfBussiness + labelgr.getRowCount() + "filterQuery" + filterQuery);

        return filterQuery;

    },

    type: 'UserList'
});
 
 

 

 

 

Hi @Community Alums 

Thank you for the inputs i have impleted the same