Create a dropdown with a list of users assigned to a task

From pmusers
Jump to: navigation, search

This example shows how to use the Derivation::getAllUsersFromAnyTask() function create a dropdown box which contains a list of the users assigned to a task


Author: Amos Batto (amos@processmaker.com)
Tested in: ProcessMaker 3.2.1 Community in Debian 8.4 with PHP 5.6.20


Call the Derivation::getAllUsersFromAnyTask() function in a trigger to return an array of the IDs of users assigned to a task. Then, use userInfo() to get information about those users and assign them to an array which is used to populate the dropdown box.

Create the following trigger which is set to be fired before the Dynaform:

$taskId = @@TASK; //set to the ID of task or use @@TASK if the current task
$d = new Derivation();
$aUsers = $d->getAllUsersFromAnyTask($taskId);
@=userList = array();
   
foreach ($aUsers as $userId) {
   $aUserInfo = userInfo($userId);
   @=userList[] = array(
       $userId,
       $aUserInfo['firstname'] .' '. $aUserInfo['lastname']
   );
}

Then, in the properties of the dropdown box in the Dynaform Designer, set the datasource to "array variable" and the data variable to: @@userList

datasourceInDropdown.png