cancel
Showing results for 
Search instead for 
Did you mean: 

Assign individual users to content programatically

motion11
Champ in-the-making
Champ in-the-making
Hi,

I am developing a workflow for a company and I came across a problem. I have to assign(invite users to content) individual users to a content in one step of my workflow. Is there a way to do something like that?

For example: (this is totally wrong but you'll maybe get a better idea of what I'm trying to achieve here Smiley Happy

bpm_package.children[0].setPermission["John Doe, 'contributor' "];

Thanks in advance,

Tom
1 REPLY 1

motion11
Champ in-the-making
Champ in-the-making
Actually I guessed this one Smiley Happy

It is possible to do this:

bpm_package.children[0].setPermission("Editor","John Doe");

But now I have another problem. I get an access denied error message in alfresco.log when I try to do it in the "transition". On "task-create" It works fine!
Why does this happen??

Here is the code :

    <task-node name="reviewTask">
        <task name="ziswf:reviewTask" swimlane="quality_manager">
            <event type="task-create">
               <script>
            </script>
      
            <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
               <script>
                  var ziswfcontentdesc = bpm_package.children[0].properties["cm:description"];
                  if (ziswfcontentdesc != '')
                  {
                  taskInstance.setVariable("ziswf_fileDescription",ziswfcontentdesc);
                  }
                                        //It works fine here
               bpm_package.children[0].removePermission("All");
               bpm_package.children[0].setPermission("Editor","lovrog");
               </script>
            </action>
         </event>

         <event type="task-end">
             <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
               <script>
                  <variable name="ziswf_qmanager" access="write"/>
                  <expression>
                     if (taskInstance.actorId != null)
                        people.getPerson(taskInstance.actorId);
                     else
                        person;
                  </expression>
               </script>
            </action>
         </event>
        </task>

        <transition name="reject" to="rejectedTask" />
        <transition name="approve" to="isDirectApproved" >
         <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
            <script>
               var carrier = ziswf_carrier.properties["cm:userName"];
               bpm_package.children[0].properties["zis:QualityManager"]=ziswf_qmanager.properties["cm:userName"];
               bpm_package.children[0].properties["zis:Requester"]=initiator.properties["cm:userName"];
               var pendingfolder = companyhome.childByNamePath("/Intranet/Quality Management/Pending");
//Here is the problem, the following code marked as comment won't work
               //bpm_package.children[0].takeOwnership();
               //bpm_package.children[0].removePermission("All");
               //bpm_package.children[0].setPermission("Editor", "zvonimirk");
               bpm_package.children[0].save();
                  if (pendingfolder != null)
                     {
                     bpm_package.children[0].move(pendingfolder);
                     }
            </script>
         </action>
      </transition>
    </task-node>


All ideas are welcome!