How to retrieve the outcome chosen in the ProcForm controller

I am working on a workflow task with multiple outcomes that uses custom proc forms instead of the standard one. Is there a way for me to retrieve what outcome the user came from?

For example, if I have a task with a Yes and a No outcome, how can I tell from the proc form controller that the user chose the Yes outcome?

Thanks!

It’s been a few days, just wondering if anyone has an answer for this. If it’s not possible, that’s something I would like to know as well.

Hi!
If I understand your question properly you want to operate with all possible outcomes from you custom CUBA screen in modeler. You can easily do it after specifying outcomes in your screen within special annotation @Outcome,
see corresponding doc chapter - Declare Task Outcomes for the Modeler
Also in your screen class you can complete task with desired oucome using processFormContext.taskCompletion().withOutcome(...),
see Using the ProcessFormContext

Thanks for the reply! We’re not using the BProc add-on, this is something we’re building with the bpm add-on, so what you listed won’t work for me.

Currently the only information I need from the proc form screen controller is the outcome the user selected (for example “Yes”, “No”, or some other outcome) prior to getting directed to that custom proc form. The reason I’m asking this is because there are additional logic I need to process based on which outcome it came from.

The alternative solution would be to create another custom proc form exclusively for that outcome, but I’m trying to avoid that since the behavior and layout of the proc form is mostly the same.

In Jmix BPM add-on we use almost the same approach for working with outcomes and processFormContext, so it will be applicable for BPM too.

I need from the proc form screen controller is the outcome the user selected (for example “Yes”, “No”, or some other outcome) prior to getting directed to that custom proc form

Is it possible to use subscription to selected outcome, in your custom screen they modeled as buttons I guess. Wil it be a possible solution for you?

We’re working on Cuba Platform 7.1.6. I don’t think I have access to those special annotations (@ProcessForm and @Outcome) or ProcessFormContext. Do you have any code sample of how that would work with just the bpm-addon?

Is it possible to use subscription to selected outcome, in your custom screen they modeled as buttons I guess. Wil it be a possible solution for you?

The outcome buttons aren’t part of my custom proc form, the outcome buttons are generated from a default Cuba screen which is just a list of buttons based on the outcomes of the task. My custom proc form displays afterwards once the user has picked an outcome, so I’m just trying to figure out how to retrieve the outcome name from the user input in the proc form controller.

Sorry, I’m a little bit confused which bpm add-on are you using, we provide Bproc add-on for Cuba and BPM add-on for Jmix, what do you mean just the bpm-addon?
Could you please attach your test project? It would be better to see your build.gradle and proc form controller.

Hello again Kuo Hong!
It seems that you are using ancestor of BProc - the BPM add-on based on activity framework. After completion of userTask it should store outcome in process variables, see Transitions Depending on Task Outcomes.

When a user completes the task, its result is written to the process variable with the name generated as [taskId]_result . The variable type is ProcTaskResult .

Have you tried that? I’ve put the code below in serviceTask right after userTask and it works for me

    @Inject
    private ProcessVariablesService processVariablesService;
    @Inject
    RuntimeService runtimeService;

    public void snapshot() {
        List<ProcessInstance> processInstances = runtimeService
                .createProcessInstanceQuery()
                .active()
                .processDefinitionKey(PROCESS_DEFINITION_KEY)
                .list();
        Map<String, Object> processVariables = processVariablesService.getVariables(processInstances.get(0).getId());
        for (Map.Entry<String, Object> entry : processVariables.entrySet()) {
            log.info("found variable {} with value {}", entry.getKey(), entry.getValue() == null ? "null" : entry.getValue());
        }
    }

I’m able to fetch from process variables selected outcome

Thanks for looking into it, Artem, and yes that is the BPM add-on I’m talking about.

However, I don’t think that solution works because the task isn’t considered complete until after it’s moved past the proc form. For example, the default proc form is just a text box where user can input some comments, but they still need to complete the form for the task to be completed (if the user decides to exit out of the proc form it would still stay on that task and the user would need to repeat the action of selecting an outcome if they want to proceed).

Same logic applies to my custom proc form, and what I need is to be able to retrieve that outcome in the proc form controller class itself right after the user selected an outcome, not when the user has already completed the proc form. Hope that makes sense, and thanks for the help.

You can subscribe on init event in your procForm controller class and operate with selected outcome

    @Subscribe
    protected void init(InitEvent initEvent) {
        ScreenOptions options = initEvent.getOptions();
        if (options instanceof MapScreenOptions) {
            Map<String, Object> params = ((MapScreenOptions) options).getParams();
            Object outcome = params.get("outcome");
            log.info("selected outcome {}", outcome);

            //your custom logic there
            initMyCustomFormBasedOnOutcome(outcome);
        }
    }

So you can apply your logic based on selected outcome in screen controller.

That’s exactly what I needed, thanks!