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:
My problem is I can't find this multiple thing :D 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:
On the Form page add a HTML Widget at the bottom of the page with the following code as a CONSTANT;
//hide all file widgets on load
var noOfFiles = 0;
var maxFiles = 20;
for (var i=1; i<=maxFiles; i++){
document.getElementById('F'+i).style.display = "none";
}
function addAFile(){
// add a file opens (shows) another file
noOfFiles++;
document.getElementById('F'+noOfFiles).style.display = "";
}
</script>
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
Comments
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:
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.
Hi Seàn, I can see the idea. Theoretically, it should work, I'll try this right away. Thanks for your help.
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:
and the server logs the following errors: http://pastebin.com/HiD8A53H
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!!
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:
I desperately tried this
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?
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:
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.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
Comments
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 :(