
- 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 10:52 PM
Hi @Community Alums ,
If my answer helped you, can you please mark as accepted solution & hit helpful button. It will help other mates as well
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-21-2024 11:51 PM
Hi @Community Alums ,
You can also follow below example.
var arr = ['a', 'b', 'c', '123', 'xyz']; var arrUtil = new ArrayUtil(); console.log(arrUtil.indexOf(arr, 'c'));
Thanks,
Pratik Malviya
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-21-2024 11:54 PM
Hi @Community Alums ,
You can also try below.
var arr = ['a', 'b', 'c', '123', 'xyz'];
var arrUtil = new ArrayUtil();
gs.print(arrUtil.indexOf(arr, 'c'));
Thanks,
Pratik Malviya