Help with a business rule on the HR Service table

Rob Sestito
Mega Sage

Hey Team,

I am trying to accomplish something through a business rule that was created for us.

The business rule originally is the following:

(function executeRule(current, previous /*null when async*/) {

	// Add your code here
	if(!gs.getUser().isMemberOf('Employee Relations')) {
		current.addEncodedQuery('name!=Complex ER Case');
	}

})(current, previous);

I am trying to add one more group to this business rule. However, the things I have tried has not been working.

Here is what I have tried:

(function executeRule(current, previous /*null when async*/) {

	// Add your code here
	if(!gs.getUser().isMemberOf('Employee Relations') || !gs.getUser().isMemberOf('Ask HR Team')) {
		current.addEncodedQuery('name!=Complex ER Case');
	}

})(current, previous);
(function executeRule(current, previous /*null when async*/) {

	// Add your code here
	if(!gs.getUser().isMemberOf('Employee Relations') || ('Ask HR Team')) {
		current.addEncodedQuery('name!=Complex ER Case');
	}

})(current, previous);

Among a few others - but nothing seems to be working for me. I tried created a second business rule only for Ask HR Team to run in a different order, I tried a second IF statement within the original business rule, but unable to get it to work. I need to hide the service unless someone is a member of those two groups shown in the script.

Cheers,

-Rob

1 ACCEPTED SOLUTION

Rob Sestito
Mega Sage

@TrevorK  & @jwalton -

I got it - the system for some odd reason does not like the name 'ask hr team'.

There is another group that myself and other admins are in which is HR Technology. I used that in a simple OR statement and it is working just right.

(function executeRule(current, previous /*null when async*/ ) {

    if (!gs.getUser().isMemberOf('HR Technology') || (!gs.getUser().isMemberOf('Employee Relations'))) {

        current.addEncodedQuery('name!=Complex ER Case');

    }

})(current, previous);

Thank you both for responding and helping me out with this.

Cheers,

-Rob

View solution in original post

7 REPLIES 7

TrevorK
Kilo Sage

There are two scenarios here, I'm just not sure which you are looking for:

  1. A user is not a part of Employee Relations AND a user is not a part of Ask HR Team. This means we are checking if the user is part of both groups, not just one.
    1. if (!gs.getUser().isMemberOf('Employee Relations') && !gs.getUser().isMemberOf('Ask HR Team')) 
  2. A user is not a part of one of Employee Relations / Ask HR Team. This means we are checking if the user is part of either group.
    1. if (!gs.getUser().isMemberOf('Employee Relations') || !gs.getUser().isMemberOf('Ask HR Team')) 

I am just not sure I quite understand what you are looking to achieve. Option 1 seems to be what you are asking for when you said: 

I need to hide the service unless someone is a member of those two groups shown in the script.

Option 1 would be the what you ask for - if someone is not a member of both of the groups, hide the Complex Case. If someone is a member of one of the groups, the Complex Case is still hidden; Complex Case is only displayed if you are a member of both groups.

 

Did I interpret what you were looking for right? I tried to write it out in words so hopefully it makes sense whether you are looking for something else.

 

If you think you are having an issue with the Ask HR Team, the common place for an error is with the name. You could do this to validate:

var gr = new GlideRecord("sys_user_group");
gr.get("SYS_ID_OF_GROUP");

var askhrteam = gr.name;

if (!gs.getUser().isMemberOf('Employee Relations') && !gs.getUser().isMemberOf(askhrteam)) 

Manipulate the if statement however you need. But that would just help you validate the name (perhaps someone left a double space in there somewhere?) if that's a concern.

Hello,

Along with what I said above about this BR to jwalton, I believe this BR is saying: "unless you are a member of the Employee Relations group, I will hide this hr service on the service table".

Overall this makes no sense to me to be hidden from an Admin. We are the only ones creating and/ or modifying services. This BR was built by a 3rd party consultant before my time, and I do not understand the motive behind this.

If I am not apart of the employee relations group, I cannot see it. That is why I tried modifying the script to just say "employee relations OR ask hr team.

I tried your way with getting the sys_id to the group but that did not work. I logged in as a person not in either of those groups, and I saw the hr service (this is another admin). I then changed it from && to || - and that person could not see the service. I then added that person back into the Ask hr team and still could not see the service.

So - I am feeling rather lost with this. I also, rather than trying to get the sys_id, tried to copy the name from the name field exactly and that did not work either (regarding your comment about there being an accidental additional space).

Any other suggestions? I personally think the BR should not even be there and would love to just make it inactive. But since it was before my time here, and other admins believe this BR is hiding the service from the Portal (unless you are in the ER group), it has to stay.

Thanks,

-Rob

Rob Sestito
Mega Sage

@TrevorK  & @jwalton -

I got it - the system for some odd reason does not like the name 'ask hr team'.

There is another group that myself and other admins are in which is HR Technology. I used that in a simple OR statement and it is working just right.

(function executeRule(current, previous /*null when async*/ ) {

    if (!gs.getUser().isMemberOf('HR Technology') || (!gs.getUser().isMemberOf('Employee Relations'))) {

        current.addEncodedQuery('name!=Complex ER Case');

    }

})(current, previous);

Thank you both for responding and helping me out with this.

Cheers,

-Rob