How to obtain the Output variables in a Kogito Custom Task

350 Views Asked by At

I have created a Custom Task in my BPMN and have written a handler extending KogitoWorkItemHandler. The input values were obtained as the parameters and the result was pushed back as a Map<String, Object>. This was working fine in case of an single varaible.

When in case using multiple custom object inputs and expecting multiple custom object outputs, how to identify the specific output variable name corresponding to the same custom object as input, so that it can be assigned correctly?

1

There are 1 best solutions below

0
On

In order to solve, we can pick the ioSpec from the currently running Node instance and then get the DataDefinition of the variables we need to use as results.

 WorkItemNode node =(WorkItemNode) workItem.getNodeInstance().getNode();
        IOSpecification ioSpec = node.getIoSpecification();
        for(DataDefinition dataDefinition : ioSpec.getDataOutputs()){
            if(dataDefinition.getType().equals(fullyQualifiedName)){
                return dataDefinition.getLabel();
            }
        }

Here, the fullyQualifiedName is the name of the custom input object, whcih you can obtain from the input workItem.getParameters().get(parameter).getClass().getName(). It loops through all the output and finds out the name corresponding to the custom type of the input.