Upload document to instantiation form with other data as well,using api

how do i upload a document to my instantiation form,where i have other data as well like name,address etc. .I want to start a new case using an api call and for that i am using “/API/bpm/process/processDefID/instantiation” and sending the name and address as payload. i want to know how do i send the document data to instantiation form(in payload or call another api to upload document to instantiation form) as its mandatory to upload document in the instantiation form.

Hi,

The best way is to inspect what does the form built with the UI Designer. Basically, when the File Upload widget uploads file to a specific servlet /bonita/portal/resource/process///API/formFileUpload

This servlet will upload the file in a temp folder and return a JSON response. You have then to pass this JSON as input for your contract.

Cheers

AH HA…

Just figured out what you’re sort of asking…and this is always a problem with Bonitasoft.

You cannot preload an Instantiation form as there are NO variables etc to be used. We had this problem a lot and gave up using the Instantiation form completely for many of our processes preferring to use a POST Instantiation-form form.

The current situation is and has always been:

  1. show Instantiation form
  2. prepare variables and start case

the way we do it

  1. ignore Instantiation form
  2. execute script steps to prepare our instantiation form
  3. display our instantiation form
    4 do following steps in process

The reason for this is because when starting a case - it means Start a Case and allow the user to either Continue (when a real case is started) or Cancel (When a real case is NOT started).

Real life says I want to Do X, but when I Start X, I realize I want to Do Y. So I have to ignore X. But if I really did just start X then it will just sit in the queue consuming resources. Not good for any BPM.

If you read http://documentation.bonitasoft.com/?page=execution-sequence-states-and-transactions it may become clearer…

It took us a while to figure this out and how to fix it. In the end our processes are clear cut and unlikely ever to be started like that shown, that’s just the way it is :slight_smile:

However to give you some idea of how to get a document onto a form from an API…I can give you the following as an example - Does Not work on an Instantiation Form but does on all others:

import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.PseudoColumnUsage; import java.sql.ResultSet; import java.sql.SQLException;

conn1 = BonitaSql.newInstance (“jdbc:postgresql://”+dbhost+“:”+dbport+“/”+dbdbse, dbuser, dbusrp, new org.postgresql.Driver());
if(conn1 == null){
if(inDebuggingMode){dI++; logger.severe(dI+thisTrace+"conn1 is null "+conn1.toString());}
}
else{
if(inDebuggingMode){dI++; logger.severe(dI+thisTrace+"conn1 is not null - Connected "+conn1.toString());}
}

def query1 = "SELECT DISTINCT ON (id) * FROM documents " +
"WHERE documentname = ‘$reqdDocument’ " +
“order by documentname, uploaddate desc”

conn1.eachRow(query1){
row → if(inDebuggingMode){dI++; logger.severe(dI+thisTrace+“documentData \n”+
“\t”+row.documentid+“\n”+
“\t”+row.documentname+“\n”+
“\t”+row.documentname+“\n”+
“\t”+row.versionmajor +“\n”+
“\t”+row.versionminor +“\n”+
“\t”+row.versionmini +“\n”+
“\t”+row.uploader +“\n”+
“\t”+row.approver +“\n”+
“\t”+row.uploaddate.toString() +“\n”+
“\t”+row.approvaldate.toString() +“\n”+
“\t”+row.status +“\n”
);}

documentData = row.document;
fileName = row.documentname;
String sufix = fileName.substring(fileName.lastIndexOf(“.”));

String mimeType = GetMimeType.getMimeType(“mimeType.”+sufix);
DocumentValue docValue = new DocumentValue(documentData, mimeType, fileName.toString());
}

Create Connection
Select the document from PostgreSQL database Blob
Create Data row (we can process multiple documents to our form
Define the DocumentValue and then return this to the process for display on the screen

I can’t give you more than that as it gets corporate… :slight_smile:

The only other solution I can think of is to write your own Custom REST API that will return the document to the Instantiation form…

regards
Seán

PS: As this reply offers an answer your question, and if you like it, please Mark UP and/or as Resolved.

Do you want the user to upload the document to the Instantiation form, or do you want the process to pre-load the Instantiation form with the document before showing it to the user?

Upload can be used two ways - you need to be a little clearer with what you want/need.

thanks and regards

i want to upload the document to the instantiation form using api. Currently i am only able to send the data like name, address as payLoad in my post request . The api i am using currently to create a new case is “/API/bpm/process/processDefId/instantiation” and the payload i am sending with this post request is like this {
“orderInput” : {
“customerName” : “rashik”,
“customerEmail” : “rashikbhasin@gmail.com”,
“customerMobileNumber” : “9999999999”,
}
now what i want is to send 1 more data to my instantiation form which is the upload document data. How do i send it. I tried sending the path to a file in my system but it takes it as a string and gives error like this: “uploadedPaymentDocumentInput” : “/home/rashik/Downloads/picture-1.png”.
How do i send the path to the document i want to upload in my instantiation form with name,mobile number also.