# Multiple documents to upload in a single form

**URL:** <https://community.ofelia.com/t/multiple-documents-to-upload-in-a-single-form/5856>\
**Category:** Q&A\
**Created:** [20 April 2015 01:42 UTC](https://community.ofelia.com/t/multiple-documents-to-upload-in-a-single-form/5856 "2015-04-20T01:42:45Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![amine250](https://avatars.discourse-cdn.com/v4/letter/a/0ea827/32.png) [@amine250](https://community.ofelia.com/u/amine250)\
**Post date:** [20 April 2015 01:42 UTC](https://community.ofelia.com/t/multiple-documents-to-upload-in-a-single-form/5856/1 "2015-04-20T01:42:45Z")

</div>

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](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](http://i.imgur.com/fPnWPFD.png)

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

Thanks for the answers, in advance.  
Amine.

---

<div class="post-metadata">

**Author:** ![Sean\_McP](https://dub1.discourse-cdn.com/flex013/user_avatar/community.ofelia.com/sean_mcp/32/932_2.png) [@Sean\_McP](https://community.ofelia.com/u/Sean_McP)\
**Post date:** [20 April 2015 10:43 UTC](https://community.ofelia.com/t/multiple-documents-to-upload-in-a-single-form/5856/2 "2015-04-20T10:43:36Z")

</div>

_This is the same answer_ as added to [another post here](http://community.ofelia.com//answers/how-create-form-hadle-multiple-file-uploads). 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

---

<div class="post-metadata">

**Author:** ![Sean\_McP](https://dub1.discourse-cdn.com/flex013/user_avatar/community.ofelia.com/sean_mcp/32/932_2.png) [@Sean\_McP](https://community.ofelia.com/u/Sean_McP)\
**Post date:** [21 April 2015 12:42 UTC](https://community.ofelia.com/t/multiple-documents-to-upload-in-a-single-form/5856/3 "2015-04-21T12:42:39Z")

</div>

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](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 🙂 )

regards  
Seán

---

<div class="post-metadata">

**Author:** ![yannick.lombardi](https://avatars.discourse-cdn.com/v4/letter/y/8e8cbc/32.png) [@yannick.lombardi](https://community.ofelia.com/u/yannick.lombardi)\
**Post date:** [20 April 2015 06:44 UTC](https://community.ofelia.com/t/multiple-documents-to-upload-in-a-single-form/5856/4 "2015-04-20T06:44:34Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![amine250](https://avatars.discourse-cdn.com/v4/letter/a/0ea827/32.png) [@amine250](https://community.ofelia.com/u/amine250)\
**Post date:** [20 April 2015 07:11 UTC](https://community.ofelia.com/t/multiple-documents-to-upload-in-a-single-form/5856/5 "2015-04-20T07:11:00Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![amine250](https://avatars.discourse-cdn.com/v4/letter/a/0ea827/32.png) [@amine250](https://community.ofelia.com/u/amine250)\
**Post date:** [20 April 2015 10:54 UTC](https://community.ofelia.com/t/multiple-documents-to-upload-in-a-single-form/5856/6 "2015-04-20T10:54:55Z")

</div>

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](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:)

---

<div class="post-metadata">

**Author:** ![amine250](https://avatars.discourse-cdn.com/v4/letter/a/0ea827/32.png) [@amine250](https://community.ofelia.com/u/amine250)\
**Post date:** [20 April 2015 11:00 UTC](https://community.ofelia.com/t/multiple-documents-to-upload-in-a-single-form/5856/7 "2015-04-20T11:00:42Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Sean\_McP](https://dub1.discourse-cdn.com/flex013/user_avatar/community.ofelia.com/sean_mcp/32/932_2.png) [@Sean\_McP](https://community.ofelia.com/u/Sean_McP)\
**Post date:** [20 April 2015 11:09 UTC](https://community.ofelia.com/t/multiple-documents-to-upload-in-a-single-form/5856/8 "2015-04-20T11:09:37Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![amine250](https://avatars.discourse-cdn.com/v4/letter/a/0ea827/32.png) [@amine250](https://community.ofelia.com/u/amine250)\
**Post date:** [20 April 2015 13:02 UTC](https://community.ofelia.com/t/multiple-documents-to-upload-in-a-single-form/5856/9 "2015-04-20T13:02:54Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Sean\_McP](https://dub1.discourse-cdn.com/flex013/user_avatar/community.ofelia.com/sean_mcp/32/932_2.png) [@Sean\_McP](https://community.ofelia.com/u/Sean_McP)\
**Post date:** [20 April 2015 13:48 UTC](https://community.ofelia.com/t/multiple-documents-to-upload-in-a-single-form/5856/10 "2015-04-20T13:48:17Z")

</div>

Theoretically? 🙂

Of course it will work…I do it myself! 🙂

regards 🙂

---

<div class="post-metadata">

**Author:** ![amine250](https://avatars.discourse-cdn.com/v4/letter/a/0ea827/32.png) [@amine250](https://community.ofelia.com/u/amine250)\
**Post date:** [20 April 2015 14:04 UTC](https://community.ofelia.com/t/multiple-documents-to-upload-in-a-single-form/5856/11 "2015-04-20T14:04:47Z")

</div>

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](http://i.imgur.com/rZyPNQw.png)

and the server logs the following errors:  
[http://pastebin.com/HiD8A53H](http://pastebin.com/HiD8A53H)

---

<div class="post-metadata">

**Author:** ![Sean\_McP](https://dub1.discourse-cdn.com/flex013/user_avatar/community.ofelia.com/sean_mcp/32/932_2.png) [@Sean\_McP](https://community.ofelia.com/u/Sean_McP)\
**Post date:** [20 April 2015 14:05 UTC](https://community.ofelia.com/t/multiple-documents-to-upload-in-a-single-form/5856/12 "2015-04-20T14:05:41Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![amine250](https://avatars.discourse-cdn.com/v4/letter/a/0ea827/32.png) [@amine250](https://community.ofelia.com/u/amine250)\
**Post date:** [20 April 2015 15:00 UTC](https://community.ofelia.com/t/multiple-documents-to-upload-in-a-single-form/5856/13 "2015-04-20T15:00:55Z")

</div>

Thank you Seàn for the precious help I get closer and closer 🙂  
I still need one thing 🙂 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!!

---

<div class="post-metadata">

**Author:** ![Sean\_McP](https://dub1.discourse-cdn.com/flex013/user_avatar/community.ofelia.com/sean_mcp/32/932_2.png) [@Sean\_McP](https://community.ofelia.com/u/Sean_McP)\
**Post date:** [20 April 2015 15:07 UTC](https://community.ofelia.com/t/multiple-documents-to-upload-in-a-single-form/5856/14 "2015-04-20T15:07:49Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![amine250](https://avatars.discourse-cdn.com/v4/letter/a/0ea827/32.png) [@amine250](https://community.ofelia.com/u/amine250)\
**Post date:** [21 April 2015 01:16 UTC](https://community.ofelia.com/t/multiple-documents-to-upload-in-a-single-form/5856/15 "2015-04-21T01:16:15Z")

</div>

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](http://i.imgur.com/srja8zp.png)

I desperately tried this

![b](http://i.imgur.com/Yupbh6a.png)

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?

---

<div class="post-metadata">

**Author:** ![amine250](https://avatars.discourse-cdn.com/v4/letter/a/0ea827/32.png) [@amine250](https://community.ofelia.com/u/amine250)\
**Post date:** [21 April 2015 21:34 UTC](https://community.ofelia.com/t/multiple-documents-to-upload-in-a-single-form/5856/16 "2015-04-21T21:34:07Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![amine250](https://avatars.discourse-cdn.com/v4/letter/a/0ea827/32.png) [@amine250](https://community.ofelia.com/u/amine250)\
**Post date:** [22 April 2015 14:33 UTC](https://community.ofelia.com/t/multiple-documents-to-upload-in-a-single-form/5856/17 "2015-04-22T14:33:43Z")

</div>

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 😃

---

<div class="post-metadata">

**Author:** ![Sean\_McP](https://dub1.discourse-cdn.com/flex013/user_avatar/community.ofelia.com/sean_mcp/32/932_2.png) [@Sean\_McP](https://community.ofelia.com/u/Sean_McP)\
**Post date:** [22 April 2015 14:59 UTC](https://community.ofelia.com/t/multiple-documents-to-upload-in-a-single-form/5856/18 "2015-04-22T14:59:04Z")

</div>

Glad I could help, a beer it is then! 🙂

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

Hope it goes well,  
regards
