AnsweredAssumed Answered

takeOwnership and setOwner in workflow

Question asked by e-no91 on May 30, 2014
In my workflow processdefinition.xml, I have this line of code:


<task-node name="approved">
        <transition name="" to="end">
<action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
<runas>admin</runas>
<script>
logger.log(bpm_package.children.length);

var dest = companyhome.childByNamePath(bpm_approveDestination);

if(bpm_approveDestination.equals("Sites/ar-rahnutest/documentLibrary/PAPARAN"))
{

logger.log("not set");
bpm_package.children[0].setOwner("GROUP_KETUA URUSETIA SEKRETARIAT");
logger.log("set");
if(bpm_package.children[0].mimetype!="application/pdf")
{
logger.log("is not a pdf");
logger.log("entered if");
logger.log("not pdf");
var contentPdf = bpm_package.children[0].transformDocument("application/pdf",dest);
contentPdf.setInheritsPermissions(false);
contentPdf.setPermission("Execute","GROUP_KETUA URUSETIA SEKRETARIAT");
logger.log("execute");

}
else
{
logger.log("pdf");
var contentCopy = bpm_package.children[0].copy(dest);
contentCopy.setInheritsPermissions(false);
contentCopy.setPermission("Execute","GROUP_KETUA URUSETIA SEKRETARIAT");
}
logger.log(bpm_package.children[0].getOwner());
bpm_package.children[0].takeOwnership();
bpm_package.children[0].remove();

}
else
{
logger.log("Enter");

bpm_package.children[0].move(dest);
bpm_package.children[0].setInheritsPermissions(true);
bpm_package.children[0].removePermission("AddChildren","GROUP_URUSETIA SEKRETARIAT");
}



</script>
</action>
</transition>
    </task-node>



User A is the assignee, an Editor, and the document is owned by User B.
Since I have the <runas>admin</runas> code before running the script, I expect that User A will be the document owner, but this returns Access Denied (Permission) error.
I've tried replacing setOwner with takeOwnership(), still no luck.

I want to do this because later on the document will be moved to a folder and User A, who is supposed to be the owner (in the folder User A is a consumer), is to delete the document.

Is there anything wrong with steps?

Outcomes