And here is the code that creates the workflow
<code>
@Override
public void execute(DelegateExecution delegateExecution) throws Exception {
final Object bpm_package = delegateExecution.getVariable("bpm_package");
if (bpm_package instanceof ActivitiScriptNode) {
ActivitiScriptNode asn = (ActivitiScriptNode) bpm_package;
final NativeArray children = (NativeArray) asn.getChildren();
for (int i = 0; i < children.getLength(); i++) {
final ScriptNode node = (ScriptNode) children.get(i, children);
Map<QName, Serializable> params = new HashMap<QName, Serializable>();
params.put(WorkflowModel.PROP_DESCRIPTION, node.getName() + " needs to be reviewed again");
Date dueDate = Calendar.getInstance().getTime();
params.put(WorkflowModel.PROP_DUE_DATE, dueDate);
params.put(WorkflowModel.PROP_PRIORITY, 3);
final Object obj = delegateExecution.getVariables().get("initiator");
if(obj != null) {
ActivitiScriptNode person = (ActivitiScriptNode) obj;
// triggers property fetching via NodeService
person.getProperties();
QName QNAME_INITIATOR = QName.createQName(NamespaceService.DEFAULT_URI, WorkflowConstants.PROP_INITIATOR);
params.put(QNAME_INITIATOR, person);
params.put(WorkflowModel.ASSOC_ASSIGNEE, person);
}
final NodeRef workflowPackage = getServiceRegistry().getWorkflowService().createPackage(null);
params.put(WorkflowModel.ASSOC_PACKAGE, workflowPackage);
getServiceRegistry().getNodeService().addChild(workflowPackage, node.getNodeRef(),
WorkflowModel.ASSOC_PACKAGE_CONTAINS, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI,
QName.createValidLocalName((String) getServiceRegistry().getNodeService().getProperty(node.getNodeRef(), ContentModel.PROP_NAME))));
final WorkflowDefinition adhocDef = getServiceRegistry().getWorkflowService().getDefinitionByName("activiti$activitiAdhoc");
final WorkflowPath adhoc = getServiceRegistry().getWorkflowService().startWorkflow(adhocDef.getId(), params);
if (log.isDebugEnabled())
log.debug("###created ad-hoc notify workflow for node " + node.getName());
}
}
}
</code>