You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

You can use this code block and put into the Bean Shell 

import java.util.Collection;
import org.joget.apps.app.service.AppUtil;
import org.joget.directory.model.User;
import org.joget.directory.model.service.ExtDirectoryManager;
import org.joget.workflow.shark.model.dao.WorkflowAssignmentDao;
 
ExtDirectoryManager directoryManager = (ExtDirectoryManager) AppUtil.getApplicationContext().getBean("directoryManager");
WorkflowAssignmentDao workflowAssignmentDao = (WorkflowAssignmentDao) AppUtil.getApplicationContext().getBean("workflowAssignmentDao");
//set groupId
String groupId = "G-001";
//Get users of the group using directory manager, sorted by firstName
Collection userList = directoryManager.getUsers(null, null, null, null, groupId, null, null, "firstName", false, null, null);
//initialize
String assignTo = "";
int lowestAssignmentCount = -1;
Collection assignees = new ArrayList();
//loop through the users
for(Object u : userList){
	User user = (User) u;
	
	//get open assignment count of the current user
	int userAssignmentSize = workflowAssignmentDao.getAssignmentSize(null, null, null, null, u.getUsername(), "open");
	
	//System.out.println(u.getUsername() + " has " + userAssignmentSize);
	if(lowestAssignmentCount == -1){
		//assign to the first person first
		lowestAssignmentCount = userAssignmentSize;
		assignTo = u.getUsername();
	}else if(userAssignmentSize < lowestAssignmentCount){
		assignTo = u.getUsername();
		lowestAssignmentCount = userAssignmentSize;
	}
}
//System.out.println("Will assign to " + assignTo);
assignees.add(assignTo);
return assignees;
  • No labels