Read in User and set in HTML Form Option

Hi Folks,

is there a quick way to read in camunda user of a spacial group and use them inside a HTML Form in an User Task.

Example: Read in all Department Heads to let an assignee of a task choose one of them for a approval. This one should be the assignee of next tast.

Thanks in advance,
Sebastian

Hi @SebLei77,

Below post might be of help to you

1 Like

This works for me, but unfortunelly the value of the cmbApprove variable contains
string:userid …

Do you know what to do? Thank you!

Hi @SebLei77,

It works properly if track by is used as in below

<select required
	cam-variable-name="cmbApprover"
	cam-variable-type="String"
	ng-model="selectedUser"
	ng-options="user as (user.firstName + ' ' + user.lastName) for user in users track by user.id">
</select>

or if ng-repeat is used

<select required
	cam-variable-name="cmbApprover"
	cam-variable-type="String"
	ng-model="selectedUser">
	<option ng-repeat="user in users" value="{{user.id}}">{{ user.firstName + ' ' + user.lastName }}</option>
</select>

Personally I don’t use cam-variable-* directives. Instead I use pure ng-model directive only and do variable manipulations utilizing javascript camForm.variableManager object as in below post

Dear all,

thank you for the information.

I added the following code snippet to my html form:

<div class="form-group">
    <label for="userSelection" class="col-sm-2 control-label">User Selection</label>
    <div class="col-sm-10">
 <select required
	cam-variable-name="cmbApprover"
	cam-variable-type="String"
	ng-model="selectedUser"
	ng-options="user.id as (user.firstName + ' ' + user.lastName) for user in users">
</select>
  <script cam-script type="text/form-script">
inject(['$scope', 'camAPI', function($scope, camAPI) {

	var groupName = 'all-users';
	var User = camAPI.resource('user');

	User.list({memberOfGroup: groupName}, function(err, data) {
		if (!err) {
			alert('Data: ' + JSON.stringify(data));
			$scope.users = data;
		}
	});
}]);
</script>
</div>
</div>
  

the user selction drop down remains empty. is there any error in my code?

Best Regards
Max

Hi @MSc_Conet,

Have you tried the code in a clean html form?
Could you please share your html from…

Hi @hassang

my html form code is:

<form name="approvalForm1" class="form-horizontal" role="form">

  <!-- read-only field -->
  <div class="form-group">
    <label for="name" class="col-sm-2 control-label">Item to be approved</label>
    <div class="col-sm-10">
      <input type="text"
             name="description"
             cam-variable-name="description"
             readonly="true"
             class="form-control" />      
    </div>
  </div>
 
    <!-- attachment -->
  <div class="form-group">
    <label for="attachments" class="col-sm-2 control-label">Attachments</label>
    <div class="col-sm-10">
      <div class="file">
        <label>
          <input type="file"
                 name="attachments"
                 cam-variable-name="attachments"
                 cam-variable-type="File"
                 cam-max-filesize="10000000"
                 class="form-control" />
        </label>
      </div>
    </div>
  </div>
    
  <!-- checkbox -->
  <div class="form-group">
    <label for="approved" class="col-sm-2 control-label">Genehmigen?</label>
    <div class="col-sm-10">
      <div class="checkbox">
        <label>
          <input type="checkbox"
                 name="approved"
                 cam-variable-name="approved"
                 cam-variable-type="Boolean"
                 checked="checked"
                 class="form-control" />
        </label>
      </div>
    </div>
  </div>
    
   <div class="form-group">
    <label for="userSelection" class="col-sm-2 control-label">User Selection</label>
    <div class="col-sm-10">
 <select required
	cam-variable-name="cmbApprover"
	cam-variable-type="String"
	ng-model="selectedUser"
	ng-options="user.id as (user.firstName + ' ' + user.lastName) for user in users">
</select>
  <script cam-script type="text/form-script">
inject(['$scope', 'camAPI', function($scope, camAPI) {

	var groupName = 'Accounting';
	var User = camAPI.resource('user');

	User.list({memberOfGroup: groupName}, function(err, data) {
		if (!err) {
			alert('Data: ' + JSON.stringify(data));
			$scope.users = data;
		}
	});
}]);
</script>
</div>      
    </div>

</form>

the user selection drop down after deployment is empty

Hi @MSc_Conet,

Try below GET REST call
/user?memberOfGroup=Accounting

https://docs.camunda.org/manual/7.15/reference/rest/user/get-query/

Does it return result?

thanks.

it returns an emtpy array. only “/user” returns all users or “/group” returns all user groups. this would be sufficient for my use case I guess. but how would I integrate this into my html form script ( in ng-model or ng-options) to have a dropdown of user groups for example ?

BR Max

Hi @MSc_Conet,

Then the code is working properly.
You need to change the filter of User.list so if your need is to get all users then replace the filter {memberOfGroup: groupName} with {}

thanks! I made it work like this - by creating an additional group allUsers which contains all users:

 <div class="form-group">
    <label for="userSelection" class="col-sm-2 control-label">additional Approver</label>
    <div class="col-sm-10">
 <select required
	cam-variable-name="additionalApprover"
	cam-variable-type="String"
	ng-model="selectedUser"
	ng-options="user.id as (user.firstName + ' ' + user.lastName) for user in users">
</select>
  <script cam-script type="text/form-script">
inject(['$scope', 'camAPI', function($scope, camAPI) {

	var groupName = 'allUsers';
	var User = camAPI.resource('user');

	User.list({memberOfGroup: groupName}, function(err, data) {
		if (!err) {
			alert('Data: ' + JSON.stringify(data));
			$scope.users = data;
		}
	});
}]);
</script>
</div>      
    </div>

the question now is in the following user task I want to assign that user as assignee with ${additionalApprover} but it does not work as it returns a String and not the user itself. Do you know how to address the additional Approver correctly?

Hi @MSc_Conet,

This expression should work as long as it is evaluated to string value represents the user Id

Hi @hassang
the variable is shown like this

so in this example the user john is correctly taken over but it does not appear in his inbox as it is string:john. Do you know what to else to do with the variable “additionalApprover” to evaluate this as string…?
BR
MAx

Hi @MSc_Conet,

Below post contains the answer to this

Hi @hassang
perfect! thank you so much :slight_smile:

Having a parallel gateway combines two approvals which I am checking afterwards in an expression as below:

image

The workflow item won’t go further although both variables are true. Do you see any mistake in the syntax?

BR
Max