0

I want to add a workflow on all files in a folder automatically thanks to a content rule. I've seen that one workflow already exists (review group) but I want to add one that permits only to Site manager to valid the document (manager review). I've add a javascript script, this is my code that don't work :

var workflow = actions.create("start-workflow");
workflow.parameters.workflowName = "jbpm$wf:parallelgroupreview";
workflow.parameters.requiredApprovePercent = 20;
workflow.parameters["bpm:workflowDescription"] = "Please review and approve: " + document.name;
workflow.parameters["bpm:assignee"] = site.listMembers(null, "manager", 0, true);
var futureDate = new Date();
futureDate.setDate(futureDate.getDate() + 7);
workflow.parameters["bpm:workflowDueDate"] = futureDate;
workflow.execute(document); 

Please, can you help me because I'm a bit confused.

Thanks !

Lilawood14
  • 35
  • 8

1 Answers1

1

You'll have to use a little tweak to get the SiteManager-Group for a document. The following snippet will start a parallel-group-review workflow. I've used the workflow that is based on activiti as I would recommed to use activiti instead of jbpm:

var ctx = Packages.org.springframework.web.context.ContextLoader.getCurrentWebApplicationContext();
var javaSiteService = ctx.getBean("siteService");
var site = javaSiteService.getSite(document.nodeRef);
var siteManagerGroup = javaSiteService.getSiteRoleGroup(site.getShortName(), "SiteManager", true);
var groupAssignee = people.getGroup(siteManagerGroup)

var workflow = actions.create("start-workflow");
workflow.parameters.workflowName = "activiti$activitiParallelGroupReview";
workflow.parameters.requiredApprovePercent = 20;
workflow.parameters["bpm:workflowDescription"] = "Please review and approve: " + document.name;
workflow.parameters["bpm:groupAssignee"] = groupAssignee;
var futureDate = new Date();
futureDate.setDate(futureDate.getDate() + 7);
workflow.parameters["bpm:workflowDueDate"] = futureDate;
workflow.execute(document);
alfrescian
  • 4,079
  • 1
  • 18
  • 20
  • Thanks for your help. I've add this script in "data dictionnary /scripts" and use it with a content rule. Managers don't have any notification on their dashbord and I've got no errors. Which tool(s) can I use to test this script ? or debug it ? – Lilawood14 Jun 25 '14 at 21:01
  • use Florian's Alfesco JS Console: https://github.com/share-extras/js-console If this script is executed outside of a rule, then you'll have to define the document variable yourself, e.g. var document = utils.getNodeFromString(yourNodeRefString); – alfrescian Jun 27 '14 at 11:58