I have this case where an activity is assigned to the HOD, but I want the wf engine to be able to assign this activity to another user in case the HOD is not available, I thought of doing this by depending on a group to be the participant instead of the HOD, but how can I add a condition that will select the user that belong to the group and also to the department of the performer?

  • No labels

6 Comments

  1. Hey there,

    The easiest way is to write a participant beanshell plugin to do all the checking and assignment. You will just need to return a array of usernames of the applicable assignees.

    Hope it helps!

    1. Thanks, I just wanted to know if I can use the same connection that I defined in my datasource, or should I hardcode the connection string and credentials into the script that I will write?

      1. We should be using the conventional way of retrieving data and should not reinvent the wheel.

        Whenever possible, try to explore and use back methods and objects that are made available to us when writing the bean shell plugin. I'm attaching a working bunch of code that will return list of users that are in the same department with the requestor and belonged to a certain group.

        Hope that this would help.

        import java.util.*;
        import org.joget.directory.model.*;
        import org.joget.plugin.base.PluginManager;
        import org.joget.directory.model.service.DirectoryManager;
        import org.joget.workflow.util.WorkflowUtil;
        
        DirectoryManager dm = (DirectoryManager) pluginManager.getBean("directoryManager");
        
        User user = dm.getUserByUsername( WorkflowUtil.getCurrentUsername() );
        Collection employments = user.getEmployments();
        Collection result = new ArrayList();
        if (employments.iterator().hasNext()){
            Employment employment = (Employment) employments.iterator().next();
            Department department = employment.getDepartment();
            Collection users = dm.getUserByDepartmentId(department.getId());
        
            for (Iterator it=users.iterator(); it.hasNext(); ) {
                User tempUser = (User) it.next();
                if(dm.isUserInGroup(tempUser.getUsername(), "HOD") )){
                    result.add(tempUser.getUsername());
                }
            }
        }
        return result;
        
        1. Hi hugo,

          i'm using v3, can u explain me more details of the code. 

          i tried it by using the map to plugin tool then copy paste the code there but it does not work, maybe i dont undertand that much about the code. you can see what im trying to achieve here,workflow variable and hash variable v3

          Thanks,

          Regards

          N.aimi F

  2. I've the same need: can you better explain the code?

    Tanks a lot.

    Bye 

  3. Why collection<group> cannot be work ?