Question

When any document is inserted in a folder I'm trying to start a custom workflow with the document attached to it. I use Alfresco community v4.2.

Wokflow works fine if I select a document then "Start a workflow". The document is correctly added to the workflow and I can complete it.

My rule is in place and execute the following script when any document is inserted (code in comments is what I've tried) :

//var workflow = actions.create("start-workflow");
var wfdef = workflow.getDefinitionByName("activiti$reviewNewFile");
//workflow.parameters["bpm:workflowDescription"] = document.name;
//workflow.parameters.workflowName = "activiti$reviewNewFile";
if(wfdef)
{
    var wfparams = new Array();
    wfparams["bpm:workflowDescription"] = document.name;
    var wfpackage = workflow.createPackage();
    //var docNode = search.findNode(document.nodeRef); 
    wfpackage.addNode(document);
    //wfpackage.addNode(docNode);
    wfdef.startWorkflow(wfpackage,wfparams);
}

//workflow.execute(document);

For the moment the script is well executed, a workflow is created but no document is added to the workflow. My document reference in the script is not null since the document's name is correctly output in the workflow.

I've read those two posts already but none of them are of any help:

EDIT: I've been able to narrow it down. My first task in the workflow is assigned to a candidateGroup and not an individual person. Group name is retrieved by the following piece of code :

<extensionElements>
    <activiti:executionListener event="start" class="org.alfresco.repo.workflow.activiti.listener.ScriptExecutionListener">
        <activiti:field name="script">
            <activiti:string>
                execution.setVariable('wf_secretairesGroup', groups.getGroup('Secretaires').getFullName());
            execution.setVariable('wf_responsablesGroup', groups.getGroup('Responsables').getFullName());
            </activiti:string>
        </activiti:field>
    </activiti:executionListener>
</extensionElements>

Part of my bpmn file :

<startEvent id="start" name="Start" activiti:formKey="wf:reviewNewFile" />

<sequenceFlow id="flow1" name="" sourceRef="start" targetRef="addCommentTask"></sequenceFlow>

<userTask id="addCommentTask" name="Add comment Task" activiti:candidateGroups="${wf_secretairesGroup}" activiti:formKey="wf:addCommentTask">
  <extensionElements>
    <activiti:taskListener event="complete" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener">
      <activiti:field name="script">
        <activiti:string>
            execution.setVariable('bpm_comment', task.getVariable('bpm_comment'));
            execution.setVariable('wf_initiator', person);
        </activiti:string>
      </activiti:field>
    </activiti:taskListener>
  </extensionElements>
</userTask>

I tried to change the addCommentTask by replacing candidateGroup with assignee, assigning it to admin and it worked... Still no idea why it works this way and not the other.

Was it helpful?

Solution

And if you do the following (change the array to object):

var wfdef = workflow.getDefinitionByName("activiti$reviewNewFile");
var wfparams = new Object();
wfparams["bpm:workflowDescription"] = document.name;
wfparams["bpm:assignee"] = people.getPerson("admin");
var wfpackage = workflow.createPackage();
wfpackage.addNode(document);
wfdef.startWorkflow(wfpackage,wfparams);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top