Process initiate with values and how to access them in Human task


Hi All,

I am trying to pass some values and start a process from a java app but not sure how do I access them in the form.

(To view the the image below, right click and choose open in a new tab)


Here is the java code:

HashMap parameters = new HashMap();
parameters.put("server.url", "http://localhost:8080");
parameters.put("", "bonita");
APITypeManager.setAPITypeAndParams(ApiAccessType.HTTP, parameters);
LoginAPI loginAPI = TenantAPIAccessor.getLoginAPI();
// log in to the tenant to create a session
APISession apiSession = loginAPI.login("walter.bates", "xxx");
// Process API
ProcessAPI processapi = TenantAPIAccessor.getProcessAPI(apiSession);
IdentityAPI identityAPI = TenantAPIAccessor.getIdentityAPI(apiSession);
User user = identityAPI.getUserByUserName("walter.bates");
//Find the List of deployed processes
final SearchOptions searchOptions = new SearchOptionsBuilder(0, 100).sort(ProcessDeploymentInfoSearchDescriptor.DEPLOYMENT_DATE, Order.DESC).done();
final SearchResult deploymentInfoResults = processapi.searchProcessDeploymentInfos(searchOptions);
Map variables = new HashMap() ;

variables.put("varA", "test");
variables.put("varC", "testa");

try {
long processDefinitionId = processapi.getProcessDefinitionId("TestPool", "1.0");
// ----- create list of operations -----
List listOperations = new ArrayList<>();
Map listVariablesSerializable = new HashMap<>();

for (String variableName : variables.keySet()) {
Object value = variables.get(variableName);
if (value != null && value instanceof Serializable) {
Serializable valueSerializable = (Serializable) value;

variableName = variableName.toLowerCase();
Expression expr = new ExpressionBuilder().createExpression(variableName, variableName, value.getClass().getName(), ExpressionType.TYPE_VARIABLE);
Operation op = new OperationBuilder().createSetDataOperation(variableName, expr);
listVariablesSerializable.put(variableName, valueSerializable);
// ----- start process instance -----
processapi.startProcess(processDefinitionId, listOperations, listVariablesSerializable);

But I am not sure how to access variables, varA and varC in BPM flow, ie in Human task or is it even correct what I am doing. If not how can I access those variables in the human task form after I start the process from Java app

(To view the the image below, right click and choose open in a new tab)


Appreciate any help.


1 answer

This one is the BEST answer!

You have to use the case variable Rest API:

Create an External API variable in your task form varA with URL: ../API/bpm/caseVariable/{{task.caseId}}/varA

Then you can bind varA.value to an input field.

The task variable is auto generated when you create a form from the Studio (Go to the Execution > Form property on a Task and click on the pen icon to create or edit a form for this task)

Depending on your use case we recommend using the BDM to design and store your data. Used with process and task contracts it is possible to generate a lot of boiler plate between the form and the process (Using the Add from data... in Contract section)

You can have a look to this documentation article for more information on that topic.




Submitted by m.sulaiman78_1417356 on Thu, 06/04/2020 - 10:30

Thanks a lot Romain.

It worked teeth_smile.png