- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2024 07:25 AM
Hey Everyone,
I need an ui action to display only if the user is in the L2 assignment group and not the team lead 1, team lead 2, or manager.
Everything works until I try to use indexOf. It isn't working for the L2 assignment groups. Below is my script include code.
What am I doing wrong? This ui action only needs to display if the current assignment group starts with L2 and the user isn't a team lead 1, team lead 2, or manager.
var showChangePriority = Class.create();
showChangePriority.prototype = Object.extendsObject(AbstractAjaxProcessor, {
checkCondition: function(current) {
if ( gs.getUser().isMemberOf(current.assignment_group).toString().indexOf("L2") > -1 && (!gs.getUser().isMemberOf(current.assignment_group.manager) || !gs.getUser().isMemberOf(current.assignment_group.u_team_lead_1) || !gs.getUser().isMemberOf(current.assignment_group.u_team_lead_2))) {
return true;
} else {
return false;
}
},
type: 'showChangePriority'
});
This is the condition field for UI action.
new showChangePriority().checkCondition(current);
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2024 08:48 AM - edited 02-26-2024 09:47 AM
Hi @Community Alums,
I see a couple of issues with the logic here (Assuming I understand what you're trying to achieve correctly)
The 'isMemberOf' function returns a boolean, as in true or false. You therefore don't need to use an additional indexOf check.
Use the following tweaks to your script to achieve the same (based on my understanding) which I've tried and tested.
I would also consider only calling this script from your UI action if the group starts with 'L2' in the first place, but the following will work
To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Helpful.
Thanks, Robbie
var showChangePriority = Class.create();
showChangePriority.prototype = Object.extendsObject(AbstractAjaxProcessor, {
checkCondition: function(current) {
if (current.assignment_group.name.startsWith('L2')
&& gs.getUser().isMemberOf(current.assignment_group)
&& gs.getUser() != current.assignment_group.manager
&& gs.getUser() != current.assignment_group.u_team_lead_1
&& gs.getUser() != current.assignment_group.u_team_lead_2
) {
return true;
} else {
return false;
}
},
type: 'showChangePriority'
});
Based on your feedback, you can also try the below:
var showChangePriority = Class.create(); showChangePriority.prototype = Object.extendsObject(AbstractAjaxProcessor, { checkCondition: function(current) { // Check if the user is in the L2 assignment group if (gs.getUser().isMemberOf(current.assignment_group) && current.assignment_group.name.startsWith("L2") && gs.getUserID() != current.assignment_group.manager && gs.getUserID() != current.assignment_group.u_team_lead_1 && gs.getUserID() != current.assignment_group.u_team_lead_2 ) { // Check if the user is not a team lead 1, team lead 2, or manager return true; // User meets the conditions } else { return false; } // User does not meet the conditions }, type: 'showChangePriority' });
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2024 09:42 AM - edited 02-26-2024 09:43 AM
Hey!
Thank you so much. Your code got the closest to what I needed. I couldn't use getUser() method because it returns the current user object. Instead, I used getUserID() method to return the sys_id of the user and compare that value to the current.assignment_group.manager sys_ids.
Below is the code that I'm using:
var showChangePriority = Class.create();
showChangePriority.prototype = Object.extendsObject(AbstractAjaxProcessor, {
checkCondition: function(current) {
// Check if the user is in the L2 assignment group
if (gs.getUser().isMemberOf(current.assignment_group) && current.assignment_group.name.startsWith("L2") &&
gs.getUserID() != current.assignment_group.manager &&
gs.getUserID() != current.assignment_group.u_team_lead_1 &&
gs.getUserID() != current.assignment_group.u_team_lead_2
) {
// Check if the user is not a team lead 1, team lead 2, or manager
return true; // User meets the conditions
} else {
return false;
} // User does not meet the conditions
},
type: 'showChangePriority'
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2024 08:03 AM
Hi @Community Alums ,
current.assignment_group
This might be the sys_id which is why indexOf isn't working for you. Try dot walking to name or getDisplayValue() and then do indexOf().
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2024 08:22 AM
gs.getUser().isMemberOf(current.assignment_group).getDisplayValue().indexOf("L2") > -1
I tried both ways, but the same issue.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2024 08:35 AM - edited 02-26-2024 08:36 AM
Looks like @Sohithanjan G's 1st point holds valid as isMemberOf will return a boolean and we are trying to find L2 from a true or false value which is not correct.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2024 08:07 AM
Please check with search() method instead of indexOf