indexOf not working as expected

Community Alums
Not applicable

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);
2 ACCEPTED SOLUTIONS

Robbie
Kilo Patron
Kilo Patron

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'
});

View solution in original post

Community Alums
Not applicable

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'
});

 

View solution in original post

12 REPLIES 12

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

 

Please mark as Accepted Solution if this solves your query and HIT Helpful if you find my answer helped you. This will help other community mates too..:)

Pratik Malviya
Tera Guru

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')); 
Please mark the appropriate response as correct answer and helpful, This may help other community users to follow correct solution.
Thanks,
Pratik Malviya

Pratik Malviya
Tera Guru

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')); 
Please mark the appropriate response as correct answer and helpful, This may help other community users to follow correct solution.
Thanks,
Pratik Malviya