Multiple documents to upload in a single form

Hi everyone,

Of course this question has been posted numerous times and I used the answers, but I got stuck at some step.

So I’ve discovered that Bonita handles documents lists and I found this http://documentation.bonitasoft.com/documents

When creating my document variable, in the documents tab of the pool, I checked Multiple.
According to the Bonita documentation (link above), the form data tab should have something that says Multiple which does the same thing I want. I don’t know if it’s not featured in the community edition (which should be mentioned).

Here’s a pic of the doc:
list of docs bonitadoc

My problem is I can’t find this multiple thing :smiley:
BTW, I’m using Bonita Community 6.5.1

Thanks for the answers, in advance.
Amine.

This is the same answer as added to another post here. Added to too many links etc…

The only way to do a variable number of documents on a form in community is a variation of:

On your form add the maximum number of file widgets you are likely to encounter; F1-F20
Add a SimpleButton called Add A File and add a HTML Attribute:

onclick="addAFile();"

On the Form page add a HTML Widget at the bottom of the page with the following code as a CONSTANT;


Don’t forget to set all the Output Operations on the files for when you click submit…

Document will be null when not added or incomplete.

regards
Seán

OK, I’m back.

Here is the way I would do it…sorry if it takes a step back a bit. That’s the way I work

Process A - get the files
Process A add a list variable “filesForAlfresco”

Step1 Form Load the files (as previously discussed)
Step1 - NOT of the Form, NOT on the Submit Button, but ON the STEP itself as an OPERATION (in the process diagram highlight the Step only) add the following code to a Script Connector:

List xList = new ArrayList(); def x;

if (inputDoc01==null){ /* do nothing / } else{x = apiAccessor.getProcessAPI().getLastDocument(processInstanceId, “inputDoc01”).getId(); xList.add(x);}
if (inputDoc02==null){ /
do nothing / } else{x = apiAccessor.getProcessAPI().getLastDocument(processInstanceId, “inputDoc02”).getId(); xList.add(x);}
if (inputDoc03==null){ /
do nothing */ } else{x = apiAccessor.getProcessAPI().getLastDocument(processInstanceId, “inputDoc03”).getId(); xList.add(x);}
etc…
return xList;

This creates a list of the document id’s of the documents in the process that have been uploaded. That’s all you need.

In the Operation Left hand “filesForAlfresco” Takes the value of the above script.

In Step2 (the iterative step)

Input List = “filesForAlfresco”;
Iterator = docID of type java.lang.long;
Map the docID to the docID of the subprocess

This will execute the subprocess for each found input document in the “filesForAlfresco” list.

In the subprocess:

You will have a variable docID of type long
and a Document, ONLY ONE, that’s all that’s needed.

Step1 has a script connector (from http://documentation.bonitasoft.com/documents )

import org.bonitasoft.engine.bpm.document.Document; import org.bonitasoft.engine.bpm.document.DocumentValue;

Document doc=apiAccessor.getProcessAPI().getDocument(sub_docId);
DocumentValue docValue=new DocumentValue(apiAccessor.getProcessAPI().getDocumentContent(doc.getContentStorageId()), doc.getContentMimeType(), doc.getContentFileName());
return docValue;

The return from the connector should be assigned to the Document Variable in the subprocess. NOTE - Change the operator to SET Document, that is not Takes the value of

You now have a document in the subprocess that you can use in Step 2, the Alfresco connector.

That’s it, can’t help any more. It will work I’m sure of it. It’s the way I’m doing mine (well almost :slight_smile: )

regards
Seán

Hi.

I think this option is only in the Subscription version of Bonita BPM.

In the Community version, if you want multiple-document in a form, you need multiple File widget.

Thank you for your answer.
That’s too bad, I had some hope :frowning:

Hi Sean,
Thank you for this precious answer.

To concrete the example I used 5 file upload widgets and I configured them all, but now I have a problem with the Alfresco connectors, I created 5 of them, so they look just like this:

![alfresco connectors][alfresco connectors]
[alfresco connectors]: http://i.imgur.com/q9VwyZX.png

Now if I don’t attach all the 5 files, logically, ones of them stay null, for example if I only attach the first file I get this in the log error:
Caused by: org.bonitasoft.engine.commons.exceptions.SObjectNotFoundException: Document not found: dossier2 for process instance: 6013

So my question is there any way to avoid executing the connector if I don’t join all of the files?

Thank you 0:)

My first file dossier1 is mandatory.
Actually I’m thinking about a groovy script that returns dossier1 whenever dossierX is null but that’s not a very elegant way to do it.

EDIT: Maybe use an exception, or system.exit in a groovy script… I’m not sure what would work.

I think the only thing you can do here is:

create a List Variable of the documents (ones that are valid of course ignoring all nulls), there is some documentation in documentation of how to pass a document from process to subprocess…

Create a MultiInstantiated step that passes the document from the List to a subprocess that then calls only one Alfreco connector for the file.

This way the Alfresco connector will only be executed the number of time necessary for the list…1 file one call, 5 files five calls.

Hope this helps regards
Seán

Hi Seàn,
I can see the idea. Theoretically, it should work, I’ll try this right away.
Thanks for your help.

Theoretically? :slight_smile:

Of course it will work…I do it myself! :slight_smile:

regards :slight_smile:

Frankly, I’m right now stuck at the part where I should ignore the null files, I don’t know really know how and where to filter them…

EDIT: I added actions for the submit button like this:

actions

and the server logs the following errors:
http://pastebin.com/HiD8A53H

on the form with the file widgets you have to add a new action (or operation, can’t remember) on the submit button. The left operand is A variable of type list ‘filesForAlfresco’, on the right hand side create a groovy script to read the documents values (if filled or null) and add filled ones to a temporary list, return the list. You can then use this list in the multiinstantiate.

It took me a while to figure it out, it’s in there somewhere, you are close…

Regards

Thank you Seàn for the precious help I get closer and closer :slight_smile:
I still need one thing :slight_smile: How to indicate the file to upload, to the alfresco connector using the multiInstanceIterator since my list is a list of DocumentValue?

Big thanks man!!

Tomorrow, I’ve been fixing a real bugger of a HTML problem all day and finally just got it right.

Off for a drink now…

But off the top of my head,

The shortened list ‘filesForAlfresco’ should go into the Iteration/List Field where you specify the docID as the iterator. Hopefully in you have the docID in the List if not you need it. In fact that’s all you need.

Map the docId to the subprocess and use it in there to fill local variables document name etc. and call alfresco.

I don’t use Alfresco but Postgres to save my documents, the principle is the same though.

Hope that works, gotta go, can’t keep the Ambassador waiting.

regards

Hi Seàn,

I don’t think it’s the same thing since the connector expects a String object which is a document in the field file to upload, just like in the following image:

a

I desperately tried this

b

and I get the following error: Declared return type class java.lang.String is not compatible with evaluated type class org.bonitasoft.engine.bpm.document.DocumentValue for expression instance

How can I get that from my Iterator named ‘instance’ of type DocumentValue?

Thank you Seàn, I got the part when I was stuck :stuck_out_tongue:

You’re a genius Seàn, this has worked so fine.
I didn’t have a sub-process and now I see why I need it.
Thank you again! I will gladly have your name in the thanks part of my internship report :smiley:

Glad I could help, a beer it is then! :slight_smile:

Yes you must have the sub process to do this right.

Hope it goes well,
regards