cancel
Showing results for 
Search instead for 
Did you mean: 

Add document to package items in JBPM workflow form via Java

leftright
Champ on-the-rise
Champ on-the-rise
Ok I need to do the following, have action button in share forms, that calls a webscript, that  webscript calls a java action,
this action creates a certain document and puts it in packageitems.
In order to accomplish this I am missing two things.
First:  How to add document to package items in java
Second: I probably need to acces to get the nodeRef of package items to achieve this?
        I fI need how can I retrieve package items node ref via forms
        (does nodeRef, show somewhere in packageitems ftl, i could do something like document.getByName/Id)
3 REPLIES 3

muralidharand
Star Contributor
Star Contributor
I used activiti engine and workflow delegates one of the case and not client side javascript / share side.

In my case, when the workflow is started, based on workflow inputs, I need to generate excel and attach the file as workflow attachment.
Below is the code snippet for your reference.
I used activiti engine and workflow delegates for this.

<java>
//Get the reference of the bpm_package ref
ActivitiScriptNode bpmPackage = (ActivitiScriptNode) executionVariables.get("bpm_package");

//Add the new document in the exsisting BPM package
nodeService.addChild(bpmPackage.getNodeRef(), newlyCreatedFile.getNodeRef(),
WorkflowModel.ASSOC_PACKAGE_CONTAINS, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI,
QName.createValidLocalName(fileName)));

</java>

Hope this may help you!

lementree
Champ on-the-rise
Champ on-the-rise
Hi This is the sample code to start workflow with adding package items, here I added only one item if you want you can add multiple.

WorkflowDefinition wd = getServiceRegistry().getWorkflowService().getDefinitionByName(wName);
if(wd==null)return;
NodeRef workflowPackage = getServiceRegistry().getWorkflowService().createPackage(null);
nodeService.addChild(workflowPackage, docRef, ContentModel.ASSOC_CONTAINS, assoc.getQName());
Map<QName, Serializable> parameters = new HashMap<QName, Serializable>();
parameters.put(WorkflowModel.ASSOC_PACKAGE, workflowPackage);
parameters.put(WorkflowModel.ASPECT_WORKFLOW_PACKAGE,workflowPackage);
parameters.put(WorkflowModel.PROP_COMMENT,comment);         
parameters.put(WorkflowModel.PROP_WORKFLOW_DUE_DATE,due);         
ArrayList<NodeRef> assignees = new ArrayList<NodeRef>();
assignees.add(assignee);
logger.debug("assignees:"+assignees);
parameters.put(WorkflowModel.ASSOC_ASSIGNEES, assignees);
WorkflowPath path = getServiceRegistry().getWorkflowService().startWorkflow(wd.getId(), parameters);
String wfPathId = path.getId();
List<WorkflowTask> wfTasks = getServiceRegistry().getWorkflowService().getTasksForWorkflowPath(wfPathId);
if (wfTasks.size() == 0)return;
WorkflowTask wfStartTask = wfTasks.get(0);
getServiceRegistry().getWorkflowService().endTask(wfStartTask.getId(), null);

ruchin78
Champ in-the-making
Champ in-the-making
Hi Lementree,

Thanks for the nice code you shared here.
I appreciate if you can let me know the way to attach more files in a workflow based on criteria "TagName" for example.
If FileName.TagName="ABC" then
Add FileName to the array
End if.

Also, how and when this script will run for multiple documents because as much I know the script runs only
When:
Items are created or enter this folder
Items are updated
Items are deleted or leave this folder

I am using Alfresco Community Edition 5.0d