How to pass a complex type in processAPI.startProcess

1
0
-1

Hi all
I want to pass a complex type to my process while I want to call the processAPI.startProcess but I totally don't know how to do this, I thought that maybe below code could help me but it couldn't.

Map<String, Serializable> inputs = new HashMap<String, Serializable>();
inputs.put("departureDate", new Date());
inputs.put("numberOfNights", 5);
inputs.put("hotelNeeded", false);
inputs.put("destination", "Tehran");
inputs.put("reason", "Traveling");
Map<String, Serializable> mainInputs = new HashMap<String, Serializable>();
mainInputs.put("travelRequestInput", (Serializable) inputs);
ProcessInstance processInstance = processAPI.startProcess(processDefinition.getId(), mainInputs);

and I got the below error:

org.bonitasoft.engine.bpm.process.ProcessExecutionException: USERNAME=jafari | org.bonitasoft.engine.bpm.contract.ContractViolationException: Error while validating expected inputs: [Expected input [travelRequestInput] is missing]

2 answers

1
0
-1
This one is the BEST answer!

https://documentation.bonitasoft.com/javadoc/api/7.5/org/bonitasoft/engi...

Right, in the javadoc of startProcess you'll see

Note: If the process instantiation contract requires inputs, you must use startProcessWithInputs(long, Map) instead, transforming initialVariables parameter as follows: in the process, define process variables initial values (expressions) with contract inputs.

ProcessInstance startProcessWithInputs(long processDefinitionId,
Map<String,Serializable> instantiationInputs)
throws ProcessDefinitionNotFoundException,
ProcessActivationException,
ProcessExecutionException,
ContractViolationException

Start an instance of the process with the specified process definition id, and provides inputs to fulfill Process Contract. See ContractDefinition for details on contracts.
Parameters:processDefinitionId - The identifier of the process definition for which an instance will be started.instantiationInputs - The couples of input name/value that allows to start a process with an instantiation contract.Returns:An instance of the process.Throws:InvalidSessionException - If the session is invalid, e.g. the session has expired.ProcessDefinitionNotFoundException - If no matching process definition is found.ProcessActivationException - If an exception occurs during activation.ProcessExecutionException - If a problem occurs when starting the process.ContractViolationException - If inputs don't fit with task contract
Since:7.0.0

Comments

Submitted by rabiei286_1360710 on Tue, 03/06/2018 - 07:08

Thank you so much for your note.
yes you were totally right, but I expected for a more clear documentation from Bonita not just a Java doc.
anyway your comment were so help full and exactly what I was asking for.

1
0
-1

Have you checked out the documentation on how to create and pass in variables? See:
https://documentation.bonitasoft.com/bonita/7.5/manage-a-process#toc1

Comments

Submitted by rabiei286_1360710 on Sat, 03/03/2018 - 07:39

Yes,I have read this before, but I'm asking for an example if you have ever tried as the documentation is not clear enough.

Notifications