cancel
Showing results for 
Search instead for 
Did you mean: 

Compare Selected User with Current User

gbanks
Confirmed Champ
Confirmed Champ

We have a workflow where users may request access to various programs external to Activiti. The request must then be approved by that individual's manager, who is specified in the request using the "People" form item.

A manager should be able to request special permissions on behalf of someone else, and then not have to approve this request. 

How do I compare the User selected in the "People" form item to the user produced by userInfoBean.getCurrentUser()?

This is my Java Code:

//Establish request_originator

var currentUser = userInfoBean.getCurrentUser()
execution.setVariable('request_originator', currentUser);

//Compare to selected manager

var originatorIsManager = 'foobar'
if(currentUser.equals(execution.getVariable('manager_of_requested_for'))){
originatorIsManager = 'yes';
} else {
originatorIsManager = 'no';
}

execution.setVariable('originator_is_manager', originatorIsManager);

See the attached image, where I display the values being returned by my Variable and the Form Field. They are identical, but my comparison is still being returned as "no."

Thank you.

1 ACCEPTED ANSWER

cjose
Elite Collaborator
Elite Collaborator


Since you are comparing execution.getVariable('manager_of_requested_for') which will be the "ID" of manager_of_requested_for, you need to get currentUser's ID for the comparison. Set currentUser as below
var currentUser = userInfoBean.getCurrentUser().getId()

View answer in original post

1 REPLY 1

cjose
Elite Collaborator
Elite Collaborator


Since you are comparing execution.getVariable('manager_of_requested_for') which will be the "ID" of manager_of_requested_for, you need to get currentUser's ID for the comparison. Set currentUser as below
var currentUser = userInfoBean.getCurrentUser().getId()