cancel
Showing results for 
Search instead for 
Did you mean: 

Add content to bpm:workflowPackage via javascript/rules

chicco0386
Champ on-the-rise
Champ on-the-rise
Hi,
I've this javascript for start a my advanced workflow, but the problem born when during the initialization when I want to add more than one document to the wf.
This is the script:
for (i=0;i<space.children.length;i++){   /*Lo script viene fatto partire nella cartella "Documenti Entranti", dove verranno create le carie cartelle per i vari uffici,    *    per accedere a queste uso i children.*/   var nome=space.children[i].name;   if (nome == "1" || nome == "2" || nome == "3"){      logger.log(nome);      var rifContenutiCartella = space.children[i].children;      var contenutoCont = rifContenutiCartella.length;      logger.log("Contenuto sottocartella "+contenutoCont);      if (presenzaContenuto(rifContenutiCartella)){         /*Aggiungo un file txt che mi raccolga tutti i nomi dei doc presi per il WF, in questo doc partirà in WF */         var docCreato = space.children[i].createFile(nome+".txt");         var contents = new Array();         docCreato.content +="ELENCO DOCUMENTI INTERESSATI NEL WORKFLOW: "         for (i=0;i<rifContenutiCartella.length;i++){            contents[i] = rifContenutiCartella[i];            docCreato.content += "\r\n\r\ "+(i+1)+") "+rifContenutiCartella[i].name;         }         var docCreatoPDF = docCreato.transformDocument("application/pdf");         for (i=0;i<contents.length;i++){            logger.log(contents[i].name);         }         var workflow = actions.create("start-workflow");         workflow.parameters.workflowName = "jbpm$wfEntePAD:EntePubblico";         workflow.parameters["bpm:workflowDescription"] = "WORKFLOW";         for (i=0;i<contents.length;i++){            workflow.parameters["bpm:workflowPackage"] = contents[i];         }         workflow.execute(docCreatoPDF);      }   }}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

The workflow start with only the document "docCreatoPDF", but I want to assignee it also the contents array document…

the problem is at the end of file:
for (i=0;i<contents.length;i++){   workflow.parameters["bpm:workflowPackage"] = contents[i];}‍‍‍‍

It's possible?
Help please
THANKS
9 REPLIES 9

sethatrothbury
Champ in-the-making
Champ in-the-making
It's rather easy to do in javascript from within the workflow. As the bpm_package is recognized as a scriptNode, we can write to it the same way we can write to any other sort of node. Your code would look something like this:
for (i=0;i<contents.length;i++){            bpm_package.addNode(contents[i]);         };‍‍‍‍‍

chicco0386
Champ on-the-rise
Champ on-the-rise
It's rather easy to do in javascript from within the workflow. As the bpm_package is recognized as a scriptNode, we can write to it the same way we can write to any other sort of node. Your code would look something like this:
for (i=0;i<contents.length;i++){            bpm_package.addNode(contents[i]);         };‍‍‍‍‍

bpm_package is undefined…
This's the error…

mrogers
Star Contributor
Star Contributor
bpm_package should exist.

Are you sure you are running Alfresco script rather than Bean Shell?

Your code should be enclosed by the following tag.
         <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">

chicco0386
Champ on-the-rise
Champ on-the-rise
No no,
I don't want to put this code into a workflow, but if you see better the code, I want to put it in a javascript file (.js), that run the specific WF and add more than one file to it via this javascript…

Have you understood what I want to do?

THANKS

mrogers
Star Contributor
Star Contributor
Your line of code:
   workflow.parameters["bpm:workflowPackage"] = contents;

Does not look correct if you want to pass in a collection of documents to a workflow.

chicco0386
Champ on-the-rise
Champ on-the-rise
Your line of code:
   workflow.parameters["bpm:workflowPackage"] = contents;

Does not look correct if you want to pass in a collection of documents to a workflow.

And so…how can I do?
THANKS

sethatrothbury
Champ in-the-making
Champ in-the-making
Oh, I get what you're trying to do.

Do you have the Alfresco-SDK checked out? There is a java class test file called "JBPMEngineTest.java" under the Repository project. Look through that, it'll give you a better idea on how to do this. Though, I'm still not sure on porting it to javascript.

chicco0386
Champ on-the-rise
Champ on-the-rise
Oh, I get what you're trying to do.

Do you have the Alfresco-SDK checked out? There is a java class test file called "JBPMEngineTest.java" under the Repository project. Look through that, it'll give you a better idea on how to do this. Though, I'm still not sure on porting it to javascript.

Thanks, but I've solved writing the javascript in the start-node of the wf…

THANKS A LOT FOR THE RESPONSE

kbootz
Champ in-the-making
Champ in-the-making
Can you post the solution? I'm also receiving a null bpm_package error …

Thanks