<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Get all users inside ScriptTaskListener in Alfresco Forum</title>
    <link>https://connect.hyland.com/t5/alfresco-forum/get-all-users-inside-scripttasklistener/m-p/17258#M7639</link>
    <description>&lt;P&gt;Hello, dear community!&lt;/P&gt;&lt;P&gt;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?&lt;/P&gt;&lt;P&gt;What i want:&lt;BR /&gt;1) Get all users existing in my system.&lt;BR /&gt;2) Filter them using "organization" field (must equals to initiator.property.organization).&lt;BR /&gt;3) Distribute filtered users (their userNames, I think) to execution variables based on their groups.&lt;BR /&gt;4) Put necessary variable into activiti:candidateUsers of my userTasks.&lt;/P&gt;&lt;P&gt;I will be gratefull for any tips or solutions of the issue.&lt;/P&gt;&lt;P&gt;Code fragments:&lt;/P&gt;&lt;PRE&gt;    &amp;lt;userTask id="myTask1" name="01. My Task 1"
            activiti:assignee="${initiator.properties.userName}"
            activiti:formKey="ilm:customSimpleForm"&amp;gt;
        &amp;lt;extensionElements&amp;gt;
            &amp;lt;activiti:taskListener event="create"
                    class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener"&amp;gt;
                &amp;lt;activiti:field name="script"&amp;gt;
                    &amp;lt;activiti:string&amp;gt;
                        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);

                    &amp;lt;/activiti:string&amp;gt;
                &amp;lt;/activiti:field&amp;gt;
            &amp;lt;/activiti:taskListener&amp;gt;
        &amp;lt;/extensionElements&amp;gt;
    &amp;lt;/userTask&amp;gt;
...
    &amp;lt;userTask id="myTask2" name="02. My Task 2"
            activiti:candidateUsers="${assignees_from_group_a}"
            activiti:formKey="ilm:customSimpleForm"&amp;gt;
...
...
    &amp;lt;/userTask&amp;gt;
...
    &amp;lt;userTask id="myTask3" name="03. My Task 3"
            activiti:candidateUsers="${assignees_from_group_b}"
            activiti:formKey="ilm:customSimpleForm"&amp;gt;
...
...
    &amp;lt;/userTask&amp;gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 19 Sep 2019 13:31:43 GMT</pubDate>
    <dc:creator>ProkhorovD</dc:creator>
    <dc:date>2019-09-19T13:31:43Z</dc:date>
    <item>
      <title>Get all users inside ScriptTaskListener</title>
      <link>https://connect.hyland.com/t5/alfresco-forum/get-all-users-inside-scripttasklistener/m-p/17258#M7639</link>
      <description>&lt;P&gt;Hello, dear community!&lt;/P&gt;&lt;P&gt;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?&lt;/P&gt;&lt;P&gt;What i want:&lt;BR /&gt;1) Get all users existing in my system.&lt;BR /&gt;2) Filter them using "organization" field (must equals to initiator.property.organization).&lt;BR /&gt;3) Distribute filtered users (their userNames, I think) to execution variables based on their groups.&lt;BR /&gt;4) Put necessary variable into activiti:candidateUsers of my userTasks.&lt;/P&gt;&lt;P&gt;I will be gratefull for any tips or solutions of the issue.&lt;/P&gt;&lt;P&gt;Code fragments:&lt;/P&gt;&lt;PRE&gt;    &amp;lt;userTask id="myTask1" name="01. My Task 1"
            activiti:assignee="${initiator.properties.userName}"
            activiti:formKey="ilm:customSimpleForm"&amp;gt;
        &amp;lt;extensionElements&amp;gt;
            &amp;lt;activiti:taskListener event="create"
                    class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener"&amp;gt;
                &amp;lt;activiti:field name="script"&amp;gt;
                    &amp;lt;activiti:string&amp;gt;
                        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);

                    &amp;lt;/activiti:string&amp;gt;
                &amp;lt;/activiti:field&amp;gt;
            &amp;lt;/activiti:taskListener&amp;gt;
        &amp;lt;/extensionElements&amp;gt;
    &amp;lt;/userTask&amp;gt;
...
    &amp;lt;userTask id="myTask2" name="02. My Task 2"
            activiti:candidateUsers="${assignees_from_group_a}"
            activiti:formKey="ilm:customSimpleForm"&amp;gt;
...
...
    &amp;lt;/userTask&amp;gt;
...
    &amp;lt;userTask id="myTask3" name="03. My Task 3"
            activiti:candidateUsers="${assignees_from_group_b}"
            activiti:formKey="ilm:customSimpleForm"&amp;gt;
...
...
    &amp;lt;/userTask&amp;gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 19 Sep 2019 13:31:43 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-forum/get-all-users-inside-scripttasklistener/m-p/17258#M7639</guid>
      <dc:creator>ProkhorovD</dc:creator>
      <dc:date>2019-09-19T13:31:43Z</dc:date>
    </item>
    <item>
      <title>Re: Get all users inside ScriptTaskListener</title>
      <link>https://connect.hyland.com/t5/alfresco-forum/get-all-users-inside-scripttasklistener/m-p/17259#M7640</link>
      <description>&lt;P&gt;You could use the Script API root scope object "people" and its &lt;A href="https://docs.alfresco.com/6.1/references/API-JS-getPeoplePaging.html" target="_self" rel="nofollow noopener noreferrer"&gt;getPeoplePaged&lt;/A&gt; 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 &lt;A href="https://docs.alfresco.com/6.1/references/API-JS-query.html" target="_self" rel="nofollow noopener noreferrer"&gt;query&lt;/A&gt; 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:&lt;/P&gt;
&lt;P&gt;TYPE:"cm&lt;img id="smileytongue" class="emoticon emoticon-smileytongue" src="https://connect.hyland.com/i/smilies/16x16_smiley-tongue.png" alt="Smiley Tongue" title="Smiley Tongue" /&gt;erson" AND =cm:&lt;SPAN class="pl-s"&gt;organizationId&lt;/SPAN&gt;:"ACME"&lt;/P&gt;
&lt;P&gt;(the search term "ACME" would be based on the organisation of the initiator)&lt;/P&gt;
&lt;P&gt;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.&lt;/P&gt;</description>
      <pubDate>Thu, 19 Sep 2019 19:51:13 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-forum/get-all-users-inside-scripttasklistener/m-p/17259#M7640</guid>
      <dc:creator>afaust</dc:creator>
      <dc:date>2019-09-19T19:51:13Z</dc:date>
    </item>
  </channel>
</rss>

