start workflow using alfresco java script api or through web script

不羁岁月 提交于 2019-12-06 05:44:41

This code runs fine if:

  • docNode is not null. You should add a check for this.
  • Your group exists. Probably worth adding a check for this.
  • The workflow exists with the ID specified. Use the workflow console to confirm this. For example, the ID your provided is not an out-of-the-box workflow. If it is custom, maybe you haven't deployed the workflow successfully or you have the ID incorrect.

Also, do not use a variable called "workflow". Alfresco already defines a root-scoped object called "workflow". Speaking of that, feel free to use the workflow JavaScript API to invoke your workflow instead of an action. Either should work, though.

I ran your code successfully using the JavaScript console and a workflow id of "activiti$activitiParallelGroupReview" (and after changing your workflow variable to workflowAct).

Using Alfresco Workflow API. Note: wfDocs holds the array of doc nodes:

// 2 days from now
var dueDate2d = new Date((new Date()).getTime() + 2*(24*60*60*1000));

// Start workflow
var wfdef = workflow.getDefinitionByName("activiti$alfGroupReview");
if (wfdef) {
    var wfparams = new Array();
    wfparams["bpm:workflowDescription"] = "Please review";
    wfparams["bpm:groupAssignee"] = people.getGroup( "GROUP_site_collaborators");
    wfparams['bpm:workflowDueDate'] = dueDate2d;
    wfparams['bpm:workflowPriority'] = 1;
    wfparams['wf:notifyMe'] = true;

    var wfpackage = workflow.createPackage();
    for each (var n in wfDocs)
        wfpackage.addNode(n);  
    var wfpath = wfdef.startWorkflow(wfpackage, wfparams);
    var tasks = wfpath.getTasks();
    for each (task in tasks)
        task.endTask(null);
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!