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)

<p><img alt="test" src="https://ibb.co/BTvQ5dP" style="width: 100px; height: 100px;" /></p>

Here is the java code:

HashMap<String, String> parameters = new HashMap<String, String>();
        parameters.put("server.url", "http://localhost:8080");
        parameters.put("application.name", "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<ProcessDeploymentInfo> deploymentInfoResults = processapi.searchProcessDeploymentInfos(searchOptions);
        Map<String, Serializable> variables = new HashMap<String, Serializable>() ;
        

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

try {
            long processDefinitionId = processapi.getProcessDefinitionId("TestPool", "1.0");
            // ----- create list of operations -----
            List<Operation> listOperations = new ArrayList<>();
            Map<String, Serializable> 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);
                    listOperations.add(op);
                    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)

<p><img alt="test" src="https://ibb.co/P6JHFcS" style="width: 100px; height: 100px;" /></p>

Appreciate any help.

Thanks

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.

HTH

Romain

Thanks a lot Romain.

It worked   laugh