Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to start an Alfresco Workflow through Javascript adding a resource

Starting using a rule and a simple javascript in Alfresco is quite easy but i'm stuck on trying to start a workflow through javascript adding a resource.

My goal is to add the document (or documents) used to start the flow, so i can obtain a reference in the "OW_ATTACHMENTS" of the Alfresco BPM of the Alfresco WorkDesk. I've tried many times with the bpm:workflowpagckage or bpm:package with no luck....help!

Edit:

  function startWorkflow(name,docNode)
{    
    var workflow = actions.create("start-workflow");
    workflow.parameters["bpm:workflowPackage"] = docNode;
    workflow.parameters.workflowName = "activiti$AdHocactivitiTimer";
    workflow.parameters["bpm:assignee"] = people.getPerson("admin");
    workflow.parameters["bpm:workflowDescription"] = "test";
    workflow.parameters["bpm:workflowPriority"] = "2";
    workflow.parameters["bpm:sendEMailNotifications"] = true;
    workflow.parameters["initiator"] = people.getPerson("admin"); 
    var today = new Date();
    var duedate = today.getDate() + 1; 
    workflow.parameters["bpm:workflowDueDate"] = duedate;
    workflow.execute(document);
}

function main()
{    
    var docNode = search.findNode(document.nodeRef); 
    var name = document.name;  
        startWorkflow(name,docNode); 
}


main();

thanks!

like image 836
Black.Jack Avatar asked Dec 18 '25 04:12

Black.Jack


1 Answers

The bpm:package or bpm_package is not available before start. So what happens you're document is added to bpm_package.

And in your workflow you can access bpm_package as a variable. And with bpm_package.addNode(doc); you can add nodes.

These nodes can be found through search/childbynamepath/xpath etc.

If you don't use the action the other way is:

var workflowAction = workflow.getDefinitionByName('activiti$AdHocactivitiTimer');
var package= workflow.createPackage();
package.addNode(document);
workflowAction.startWorkflow(package, parameters);
like image 94
Tahir Malik Avatar answered Dec 19 '25 18:12

Tahir Malik



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!