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

1
0
-1

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.

Comments

Submitted by Sean McP on Fri, 02/24/2017 - 18:53

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

Submitted by rashikbhasin on Sat, 02/25/2017 - 08:16

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.

2 answers

1
+1
-1

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

1
0
-1

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-... 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 :)

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:

  1. import java.sql.Connection;
  2. import java.sql.DriverManager;
  3. import java.sql.PreparedStatement;
  4. import java.sql.PseudoColumnUsage;
  5. import java.sql.ResultSet;
  6. import java.sql.SQLException;
  7.  
  8. conn1 = BonitaSql.newInstance ("jdbc:postgresql://"+dbhost+":"+dbport+"/"+dbdbse, dbuser, dbusrp, new org.postgresql.Driver());
  9. if(conn1 == null){
  10. if(inDebuggingMode){dI++; logger.severe(dI+thisTrace+"conn1 is null "+conn1.toString());}
  11. }
  12. else{
  13. if(inDebuggingMode){dI++; logger.severe(dI+thisTrace+"conn1 is not null - Connected "+conn1.toString());}
  14. }
  15.  
  16. def query1 = "SELECT DISTINCT ON (id) * FROM documents " +
  17. "WHERE documentname = '$reqdDocument' " +
  18. "order by documentname, uploaddate desc"
  19.  
  20. conn1.eachRow(query1){
  21. row -> if(inDebuggingMode){dI++; logger.severe(dI+thisTrace+"documentData \n"+
  22. "\t"+row.documentid+"\n"+
  23. "\t"+row.documentname+"\n"+
  24. "\t"+row.documentname+"\n"+
  25. "\t"+row.versionmajor +"\n"+
  26. "\t"+row.versionminor +"\n"+
  27. "\t"+row.versionmini +"\n"+
  28. "\t"+row.uploader +"\n"+
  29. "\t"+row.approver +"\n"+
  30. "\t"+row.uploaddate.toString() +"\n"+
  31. "\t"+row.approvaldate.toString() +"\n"+
  32. "\t"+row.status +"\n"
  33. );}
  34.  
  35. documentData = row.document;
  36. fileName = row.documentname;
  37. String sufix = fileName.substring(fileName.lastIndexOf("."));
  38.  
  39. String mimeType = GetMimeType.getMimeType("mimeType."+sufix);
  40. DocumentValue docValue = new DocumentValue(documentData, mimeType, fileName.toString());
  41. }

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... :)

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.

Notifications