Bpm process instance browse startUser id

Hi there,

can you explain how can I modify ProcessInstanceBrowse screen starter User Id?
I put this in screen.xml, but it is always null.
How can I overwrite this property?

image

I have tried ProcessStartedEvent but there I cannot modify processInstance, because it has not set fields.

Thanks in advice,
Peter Polyak

Hi,

it was incorrect behavior that already fixed there

Shortly, this field is filled by Flowable itself during the start process instance, see more detailed there - https://github.com/flowable/flowable-engine/blob/main/modules/flowable-engine/src/main/java/org/flowable/engine/impl/persistence/entity/ExecutionEntityManagerImpl.java#L291

So, in order to have filled startUserId for your process instance you need to set up Flowable org.flowable.common.engine.impl.identity.Authentication before start process, like

import io.jmix.core.security.CurrentAuthentication;
import org.flowable.common.engine.impl.identity.Authentication;

private final CurrentAuthentication currentAuthentication;

    private void setAuthenticatedUser() {
        if (currentAuthentication.isSet()) {
            Authentication.setAuthenticatedUserId(currentAuthentication.getUser().getUsername());
        }
    }

    public void startProcess() {
            setAuthenticatedUser();
            processInstance = runtimeService.startProcessInstanceById(processDefinitionData.getId(), businessKey, processVariables);
    }

Best regards,
Artem

Hi,

Our current JMIX version is 1.1.4, which already contains the fix.

I tried your solution, to set the AuthenticatedUserId before ProcessFormCreation (For example ProcessDefinitionBrowse Screen’s StartProcess)

    if (currentAuthentication.isSet()) Authentication.setAuthenticatedUserId(currentAuthentication.getUser().getUsername());
    processFormScreens.createStartProcessForm(latestProcessDefinition, this)
            .show();

But it is working kinda unpredictably. All I did was starting processes continuously without doing anything else between the starts. Sometimes it works, sometimes it’s empty.

image

Do you have any idea about this?

Regards,
Gergő

Hi,

I’m afraid that fix is not included in 1.1.4, because it has been appeared in 1.3

Unfortunately no, no any good suggestion. It would be helpful if you can share some test project with your project definition to understand the root cause.

Regards,
Artem

Hi,
Sorry I thought it was fixed in 1.1.3 not 1.3, we will just wait for that release then,

If it is still relevant regardless of the 1.3 fix,
I managed to reproduce it in a test app, all you need is to create a simple process,
(mine is just a Start → Empty User Task → End process), relog to create the menu item,
and start it multiple times with the “start process” menu item.

If you check the Process Instances screen (extended to show startUserID attribute) you can see that sometimes it saves the username.

The project is available here, 1.1.4, MySQL db

Regards,
Gergő

Hi @su.ger197,

for my point of view, it happened cause authenticated user stored in thredLocal variable, see https://github.com/flowable/flowable-engine/blob/main/modules/flowable-engine-common/src/main/java/org/flowable/common/engine/impl/identity/UserIdAuthenticationContext.java

You set up authentication before the process form is shown, in a thread, that obviously not always will be used when user click on the “Start process” button. So it is necessary to call setting up authentication in the same thread with starting a process.

Regards,
Artem