In BPM bypass the procActionsFrame with my own code

Hi, i want to let the user to update state of an entity to a particular value from a button at the browser screen (as you see on the image). The goal is show the BPM StartForm to let the user to set description and actors, and then run the process from the BPM service.

image

The StarForm shows correctly, buy after i set values and press OK button i get an exception of:

“IllegalStateException: During synchronization a new object was found through a relationship that was not marked cascade PERSIST: com.haulmont.bpm.entity.ProcInstance-0800238d-b417-f649-2b62-6a76615075bb [new].”

image

image

My code is as follow:

public class ClientesBrowse extends AbstractLookup {

    private static final String PROCESS_CODE = "promoverClienteEstado";

    @Inject
    private GroupDatasource<Clientes, UUID> clientesesDs;

    @Inject
    private ProcActionsFrame procActionsFrame;
    @Inject
    private DataManager dataManager;
    @Inject
    private Metadata metadata;
    private ProcInstance procInstance;

    public void promoverStateCliente(Component source) {

        ProcessFormService processFormService = AppBeans.get(ProcessFormService.class);
        ProcessRuntimeService processRuntimeService = AppBeans.get(ProcessRuntimeService.class);

        ProcDefinition procDefinition = dataManager.load(
                LoadContext.create(ProcDefinition.class)
                        .setQuery(new LoadContext.Query("select pd from bpm$ProcDefinition pd where pd.code = :code")
                                .setParameter("code", PROCESS_CODE))
                        .setView("procDefinition-procInstanceEdit")
        );

        procInstance = metadata.create(ProcInstance.class);
        procInstance.setProcDefinition(procDefinition);
        procInstance.setObjectEntityId(clientesesDs.getItem().getId());
        procInstance.setEntityName(clientesesDs.getItem().getMetaClass().getName());

        ProcFormDefinition startForm = processFormService.getStartForm(procInstance.getProcDefinition());
        if (startForm != null) {
            Map<String, Object> formParams = new HashMap<>();
            formParams.put("procInstance", procInstance);
            formParams.put("formDefinition", startForm);
            formParams.put("caption", "PRUEBA CAPTION");
            final Window window = openWindow(startForm.getName(), WindowManager.OpenType.DIALOG, formParams);
            window.addCloseListener(actionId -> {
                if (Window.COMMIT_ACTION_ID.equals(actionId)) {
                    String comment = null;
                    Map<String, Object> formResult = null;
                    if (window instanceof ProcForm) {
                        comment = ((ProcForm) window).getComment();
                        formResult = ((ProcForm) window).getFormResult();
                    }
                    //_startProcess(comment, formResult);
                    processRuntimeService.startProcess(procInstance, comment, formResult);
                }
            });
        }

    }
}

The “addCloseListener” never get executed, because before the exception is raised, so something inside the window is commiting data.

Best regards.

Hi,
the problem here is that the ProcInstance entity that is passed to the standard process form and to the process runtime service must be persisted.