Can I create a Bproc Process at Runtime?

Hi,

I do have a existing screen for Business Process.

I want to abstract the Bproc plugin screens, and few screens like my Task will be shown to the user directly.

I want to use Bproc Modeller for this process. I would like to give a button called “Model” which should create a process definition with a name identified by my code.

I want to link my Process Entity record and the Bproc process definition and work with that further.

How do I get this done?

Thanks,
Hari

Hi,

to get a list of user tasks you can use the bprocTaskService. You find an example in the documentation:

https://doc.cuba-platform.com/bproc-1.2/#getting-a-list-of-user-tasks

Greetings
Andreas

Hi,

I would like to give a button called “Model” which should create a process definition with a name identified by my code.

You can open a Modeler screen using the Screens API:

    @Subscribe("openModelerBtn")
    public void onOpenModelerBtnClick(Button.ClickEvent event) {
        BpmnModelerScreen bpmnModelerScreen = screens.create(BpmnModelerScreen.class, OpenMode.NEW_TAB);
        bpmnModelerScreen.setBpmnXml(...);
        bpmnModelerScreen.show();
   }

All you need to do is to prepare the XML that is passed to the bpmnModelerScreen.setBpmnXml(...) method.

The “standard” XML of the new process looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:flowable="http://flowable.org/bpmn"
             xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI"
             xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI"
             typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath"
             targetNamespace="http://www.flowable.org/processdef">
    <process id="process" name="Process" isExecutable="true">
        <startEvent id="startEvent1"></startEvent>
    </process>
    <bpmndi:BPMNDiagram id="BPMNDiagram_process">
        <bpmndi:BPMNPlane bpmnElement="process" id="BPMNPlane_process">
            <bpmndi:BPMNShape bpmnElement="startEvent1" id="BPMNShape_startEvent1">
                <omgdc:Bounds height="30.0" width="30.0" x="150.0" y="150.0"></omgdc:Bounds>
            </bpmndi:BPMNShape>
        </bpmndi:BPMNPlane>
    </bpmndi:BPMNDiagram>
</definitions>

You may modify the process id and name each time you open the modeler screen.

I want to link my Process Entity record and the Bproc process definition and work with that further.

This can be done using the process definition id. If you create a process definition with a new name and id for each instance of your process entity, then just save this process definition id somewhere in your entity. You’ll always be able to find a process definition by this id.

Hi,

Thanks for your detailed reply.

I hope you meant the process definition id by the ID which i have to set in the modeler for each process.

Is there an API for creating this process XML file? Or I should use String Utils and wire this XML?

Thanks,
Hari

Is there an API for creating this process XML file? Or I should use String Utils and wire this XML?

You can create the file in any way you like.

You can put the XML file with some placeholder somewhere inside your source code, read it using the Resources service and then replace the placeholder with the process id.

Also, you may work with this file using any library for working with XML - it’s all up to you.