camunda / camunda-modeler

An integrated modeling solution for BPMN, DMN and Forms based on bpmn.io.
https://camunda.com/products/modeler
MIT License
1.5k stars 481 forks source link

Copying user task with linked Camunda form not working #4658

Open philippfromme opened 13 hours ago

philippfromme commented 13 hours ago

Describe the bug

When copying a user task with a linked Camunda form the result is unexpected.

Camunda_Modeler_JRT1orWwcx

The XML before:

<?xml version="1.0" encoding="UTF-8"?>
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:zeebe="http://camunda.org/schema/zeebe/1.0" xmlns:modeler="http://camunda.org/schema/modeler/1.0" id="Definitions_0uh0gs4" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="5.28.0" modeler:executionPlatform="Camunda Cloud" modeler:executionPlatformVersion="8.6.0">
  <bpmn:process id="Process_1" isExecutable="true">
    <bpmn:userTask id="Activity_1">
      <bpmn:extensionElements>
        <zeebe:formDefinition formId="foo" />
      </bpmn:extensionElements>
    </bpmn:userTask>
  </bpmn:process>
  <bpmndi:BPMNDiagram id="BPMNDiagram_1">
    <bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_1">
      <bpmndi:BPMNShape id="Activity_0ftdgvn_di" bpmnElement="Activity_1">
        <dc:Bounds x="160" y="70" width="100" height="80" />
      </bpmndi:BPMNShape>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</bpmn:definitions>

The XML after:

<?xml version="1.0" encoding="UTF-8"?>
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:zeebe="http://camunda.org/schema/zeebe/1.0" xmlns:modeler="http://camunda.org/schema/modeler/1.0" id="Definitions_0uh0gs4" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="5.28.0" modeler:executionPlatform="Camunda Cloud" modeler:executionPlatformVersion="8.6.0">
  <bpmn:process id="Process_1" isExecutable="true">
    <bpmn:extensionElements>
      <zeebe:userTaskForm id="UserTaskForm_1baiutt"></zeebe:userTaskForm>
    </bpmn:extensionElements>
    <bpmn:userTask id="Activity_1">
      <bpmn:extensionElements>
        <zeebe:formDefinition formId="foo" />
      </bpmn:extensionElements>
    </bpmn:userTask>
    <bpmn:userTask id="Activity_2">
      <bpmn:extensionElements>
        <zeebe:formDefinition formKey="camunda-forms:bpmn:UserTaskForm_1baiutt" />
      </bpmn:extensionElements>
    </bpmn:userTask>
  </bpmn:process>
  <bpmndi:BPMNDiagram id="BPMNDiagram_1">
    <bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_1">
      <bpmndi:BPMNShape id="Activity_0ftdgvn_di" bpmnElement="Activity_1">
        <dc:Bounds x="160" y="70" width="100" height="80" />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="BPMNShape_0t8htyd" bpmnElement="Activity_2">
        <dc:Bounds x="290" y="70" width="100" height="80" />
      </bpmndi:BPMNShape>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</bpmn:definitions>

For some reason the pasted user task has a form key instead of a form ID indicating that the copy-paste behavior is broken.

Steps to reproduce

  1. Create user task with form ID
  2. Copy and paste
  3. Pasted user task has form key instead of form ID

Expected behavior

Pasted user task has same form ID.

Environment

Additional context

Slack: https://camunda.slack.com/archives/C0693F1NFK5/p1730297588684999

philippfromme commented 11 hours ago

Root cause

Our form definition behavior creates a new form definition and user task form when a user task is created that has an existing form definition. The idea was that you don't end up referencing the same user task form when copying and pasting a user task. Copying and pasting a user task with a form definition will remove the form definition and its form ID. We need to change the behavior so that a new user task form is only created if the existing form definition references a user task form that is already referenced by another form definition.