Get all users inside ScriptTaskListener

cancel
Showing results for 
Search instead for 
Did you mean: 
ProkhorovD
Member II

Get all users inside ScriptTaskListener

Jump to solution

Hello, dear community!

I need to get a lot of users (as objects, not usernames) in ScriptTaskListener inside my userTask. Users shoud have the same organization name with initiator. How can i get them? Is it possible?

What i want:
1) Get all users existing in my system.
2) Filter them using "organization" field (must equals to initiator.property.organization).
3) Distribute filtered users (their userNames, I think) to execution variables based on their groups.
4) Put necessary variable into activiti:candidateUsers of my userTasks.

I will be gratefull for any tips or solutions of the issue.

 

Code fragments:

 

    <userTask id="myTask1" name="01. My Task 1"
            activiti:assignee="${initiator.properties.userName}"
            activiti:formKey="ilm:customSimpleForm">
        <extensionElements>
            <activiti:taskListener event="create"
                    class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener">
                <activiti:field name="script">
                    <activiti:string>
                        execution.setVariable('bpm_sendEMailNotifications', true);
                        task.setVariable('bpm_sendEMailNotifications', true);
                        var dueDate = new Date();
                        dueDate.setDate(dueDate.getDate() + 5);
                        task.dueDate = dueDate;

                        // Get users here, filter and distribute. For example:
                        // execution.setVariable('assignees_from_group_a', userNamesStringFromManagers);
                        // execution.setVariable('assignees_from_group_b', userNamesStringFromWorkers);

                    </activiti:string>
                </activiti:field>
            </activiti:taskListener>
        </extensionElements>
    </userTask>
...
    <userTask id="myTask2" name="02. My Task 2"
            activiti:candidateUsers="${assignees_from_group_a}"
            activiti:formKey="ilm:customSimpleForm">
...
...
    </userTask>
...
    <userTask id="myTask3" name="03. My Task 3"
            activiti:candidateUsers="${assignees_from_group_b}"
            activiti:formKey="ilm:customSimpleForm">
...
...
    </userTask>

 

1 Solution

Accepted Solutions
afaust
Master

Re: Get all users inside ScriptTaskListener

Jump to solution

You could use the Script API root scope object "people" and its getPeoplePaged operation to list people in the system, and use the ScriptNode instances returned from that operation to access metadata properties to filter by organisation. But that would be quite an inefficient way to go about it. Alternatively, simply use the "search" root scope object and its query operation to perform a search for matching users. With this, you can already include more complex conditions, like checking for the organisation. A basic Alfresco FTS query could look like this:

TYPE:"cmSmiley Tongueerson" AND =cm:organizationId:"ACME"

(the search term "ACME" would be based on the organisation of the initiator)

With the resulting list, you can then do all the other tasks you listed in your post. Just note that some may require mapping the complex objects to a list of Strings, e.g. candidateUsers should be the list of user names of the person nodes.

View solution in original post

1 Reply
afaust
Master

Re: Get all users inside ScriptTaskListener

Jump to solution

You could use the Script API root scope object "people" and its getPeoplePaged operation to list people in the system, and use the ScriptNode instances returned from that operation to access metadata properties to filter by organisation. But that would be quite an inefficient way to go about it. Alternatively, simply use the "search" root scope object and its query operation to perform a search for matching users. With this, you can already include more complex conditions, like checking for the organisation. A basic Alfresco FTS query could look like this:

TYPE:"cmSmiley Tongueerson" AND =cm:organizationId:"ACME"

(the search term "ACME" would be based on the organisation of the initiator)

With the resulting list, you can then do all the other tasks you listed in your post. Just note that some may require mapping the complex objects to a list of Strings, e.g. candidateUsers should be the list of user names of the person nodes.