- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2024 06:03 AM
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)
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2024 10:42 AM
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';
- 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'
};
- To use this script include in your reference qualifier, use the following code:
javascript: new AssignmentGroupReferenceQualifier().getAssignmentGroups(current.assigned_to)
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2024 10:49 AM
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());
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2024 11:51 PM
Hi @Community Alums
Thank you for the inputs i have impleted the same