uploading another doc in the same process

Hi everybody,

I’m having problems uploading new docs using the API from Bonita. Let me explain my case.
I have a process where the user can upload some files at the instantation form and it works fine, but in some cases, they need to upload more files in other Tasks. And it is here where the problems arrive

  • The first problem is that I can not link a Doc object to a contract from this task (as I did in the instantation ofrm),
  • so I am trying to do it as it seems it use to be done with older versions, using the attachDocument method form the DocumentAPI lib, and i’m getting always the same error message : “**No signature of method: static org.bonitasoft.engine.api.DocumentAPI.attachDocument() is applicable for argument types: (java.lang.Long, java.lang.String, java.lang.String, java.lang.String, [B)**” The extrange thing is that if I look into the Bonita Doc is says that the attachDocument has the following parameters: “Document attachDocument(long processInstanceId, String documentName, String fileName, String mimeType, byte documentContent)
    throws ProcessInstanceNotFoundException,
    DocumentAttachmentException”

The source code of my operation is:

import java.util.logging.Logger
import org.bonitasoft.engine.api.DocumentAPI

Logger logger= Logger.getLogger(“org.bonitasoft”)
logger.info(“INFO Trace Start***************”)
masFotos.each{
logger.info("it.getFileName = " + it.getFileName())
logger.info("it.Content Size = " + it.getContent().size())
DocumentAPI.attachDocument( processInstanceId, it.getFileName(), it.getFileName(), “image/jpeg”, it.getContent())
logger.info(“It should arrive here if it wrorks, but it seems it doesn’t”)
}

Does anyone knows whats wrong with it?

Thank you very much,
Best Regards
Alberto

Hello,

I would suggest this way and I have verified this approach(on Bonita 7.5.4).

  1. In the Operations of the human task, add an operation with the below script(on the right-hand side)
    If taskFile is the task contract input,
    return apiAccessor.processAPI.attachDocument(processInstanceId,<unique name for this document> ,taskFile.fileName , taskFile.contentType, taskFile.content).id.toString();

NOTE: The second parameter which is the document variable name must be unique for each operation, otherwise, Bonita throws an exception that the document is already existing unless you want to update that existing document .

  1. For the above operation, select a task/process variable on the left-hand side. → this is to make the operation complete with no validation errors in the studio. You can use this variable as needed(or any other variable returned from the above engine API call). As this is a Human task, BPMN would give an INFORMATION in Validation status, if the above logic is performed in a script in the ‘Connectors out’ as a BPMN2 compliant issue.

  2. Finally, in order to check if the document has been successfully attached to the case, we can use the below REST URL( if the case is still active. Otherwise get archived document )

../API/bpm/caseDocument?p=0&c=100&f=caseId=<caseId>

Hello

I think you need to import more classes for it to work.

I use the Below code for Documents. Have a look,

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

List documentsMerged = new ArrayList();
DocumentValue dv;

if(hlsDoc)
{
hlsDoc.each { pj → // pj is a FileInputValue}
dv = new DocumentValue( pj.getContent(), null, pj.getFileName() );
documentsMerged.add(dv); }

return documentsMerged;

}

Hope this helps…

Hello Dibyajit,

Thanks for your answer.
I was trying to use the DocumentValue class but the problem is that after executing the operation I can not see the document content in the “document” table at the BonitaJournal database.

What should I do after creating a DocumentValue object to see the document added into the “document” table?

Thank you!!!
Alberto

Actually I dont use a table to store documents.
I create a Document variable in the Studio. I believe the Docs are saved in a particular location on server.
I can access these docs using Rest API.
So basically I use the Operation section for each task.
Left hand side has the Doc and right side section has value set as Script. There I use the above code.

regards