Get all users from group in cam-script directive - embedded form

Hi,
I had the same issue and searched some hours to find the solution, how to create a selectable user list in an embedded form:

  1. In an ExecutionListener you can create a variable with the UserList like this:
    List<User> userList = execution.getProcessEngineServices().getIdentityService().createUserQuery().memberOfGroup("user-group-id").list();
            ObjectValue customerDataValue = Variables.objectValue(userList)
                    .serializationDataFormat(Variables.SerializationDataFormats.JSON)
                    .create();
            execution.setVariable("users", customerDataValue);

Attention: You have to call the Listener before your Task where the embedded form is, because the embedded form will be called before your Listener.
To use the ObjectValue correclty, you will have to integrate org.camunda.spin in your project. Camunda offers a good description for this.

  1. In your embedded form you will have to call the variable you created with your Listener:
<div>
    <label for="selected_user">Choose your Gefa leader</label>
    <script cam-script type="text/form-script">
        camForm.on('form-loaded', function() {
         camForm.variableManager.fetchVariable('users');
         });
        camForm.on('variables-fetched', function() {
          $scope.gefaLeaders = camForm.variableManager.variableValue('users');
        });
    </script>
    <select cam-variable-name="selected_user"
            cam-variable-type="String"
            ng-options="c as c.id for c in users track by c">
    </select>
</div>
  1. Make sure your users have the right authorisations. They will need the authorization to READ on Resource USER and they will need rights on the Resource GROUP.

And thats it. Following these steps I was able to select users from a drop down list.

I hope this helps.