You are viewing limited content. For full access, please sign in.

Question

Question

Team Dynamic Filters - Trying to use an if statement to compare username

asked on July 24, 2017

Hello,

 

I am essentially trying to use a filter (dynamic) and compare the submitting user and the user with the role of approver and make sure they dont match. For instance if Bob submits a request but Bob is also the approver, I want it to go to approver2 instead of approver1. Is there a way to do this in the JS on forms?

If someone cant answer that but can tell me what information is passed (username, full name, etc) when it finds out the role and displays the persons name when you test the filter, that would be great. I can then use that to compare.

 

Kind of a sample that I typed up:

 

var site = $util.getValue('Where_do_you_work');
var submitter = $util.getValue('Initial_Submitter');

if ($util.getValue('Initial_Submitter')== team.findMembersByRole(site+'Approver1'))
$result=team.findMembersByRole(site+'Approver2');
else
$result=team.findMembersByRole(site+'Approver1');

 

So if the initial submitter equals the approver1 for that site, it will get passed to approver2.

 

Thank you

0 0

Replies

replied on July 24, 2017

Hi Keith,

$util.getValue('Initial_Submitter') returns a string while team.findMembersByRole(site+'Approver1') returns an array of members, so the comparison does not work.

To find the initial submitter as an array of members, you can use team.findTeamMembersByUserName() to find by username, or team.findTaskSubmitters() by step id.

To check if array of members and another array both have the same member, you can use $util.intersection().length > 0

I simplified the role to 'a' and 'b', and the script is like this:

$allUserInRole = team.findMembersByRole('b');
$submitter = team.findTaskSubmitters(1);
if ($util.intersection($allUserInRole, $submitter).length > 0) {
  $result=team.findMembersByRole('a');
} else {
  $result=team.findMembersByRole('b');
}

Besides, if you just want task to be assigned to users other than initial submitter, you could keep them with one role and use $util.difference() to remove submitter from approval list, like this:

$result=$util.difference($allUserInRole, $submitter);

 

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.