Custom Form Field Type

Hi, Im trying to add a custom form field type and I’m not sure what I’m missing or doing wrong.

I’ve created the java implementation

public class DateTimeField extends AbstractFormFieldType {

  public static final String TYPE_NAME = "dateTime";

  private String dateTimeFormat = "yyyy-MM-dd hh:mm:ss";
  private DateTimeFormatter formatter = DateTimeFormatter.ofPattern(dateTimeFormat);


  public String getName() {
    return TYPE_NAME;
  }


  public TypedValue convertToModelValue(TypedValue propertyValue) {
    Object value = propertyValue.getValue();
    if (value == null) {
      return Variables.untypedNullValue();
    } else {
      String strValue = ((String) value).trim();
      if (strValue.isEmpty()) {
        return Variables.untypedNullValue();
      }
      try {
        return Variables.untypedValue(LocalDateTime.parse(strValue, formatter), propertyValue.isTransient());
      } catch (Exception e) {
        throw new ProcessEngineException("Could not parse value '" + value + "' as dateTime using date time format '" + dateTimeFormat + "'.");
      }
    }
  }


  public TypedValue convertToFormValue(TypedValue modelValue) {
    if (modelValue.getValue() == null) {
      return Variables.stringValue(null, modelValue.isTransient());
    } else {
      return Variables.stringValue(formatter.format((LocalDateTime) modelValue.getValue()), modelValue.isTransient());
    }
  }


  @Override
  public Object convertFormValueToModelValue(Object propertyValue) {
    return null;
  }


  @Override
  public String convertModelValueToFormValue(Object modelValue) {
    return null;
  }

}

And added it as a custom form type

@Component
public class TestConfiguration extends AbstractCamundaConfiguration {

  @Override
  public void preInit(SpringProcessEngineConfiguration config) {
    config.getCustomFormTypes().add(new DateTimeField());
  }
}

In the modular I have set the form up as follows

When I start the process I get the form shown correctly, but whenever I enter any value into the Date field I get an error

How should I be doing this so a value can be entered and submitted? Ideally it would also be good to validate the input, but just wanted to get this working first :slight_smile:

Thanks,

Matt


Full bpmn below

<?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:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:camunda="http://camunda.org/schema/1.0/bpmn" id="Definitions_0zpho6t" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="3.6.0">
  <bpmn:process id="Process_1" isExecutable="true">
    <bpmn:startEvent id="StartEvent_1" name="Start workflow">
      <bpmn:extensionElements>
        <camunda:formData>
          <camunda:formField id="M_Message" label="Message" type="string" />
          <camunda:formField id="D_Action" label="Date" type="dateTime" />
        </camunda:formData>
      </bpmn:extensionElements>
      <bpmn:outgoing>SequenceFlow_12a8jo4</bpmn:outgoing>
    </bpmn:startEvent>
    <bpmn:serviceTask id="Task_163mbh3" name="Do something" camunda:delegateExpression="${blankDelegate}">
      <bpmn:incoming>SequenceFlow_12a8jo4</bpmn:incoming>
      <bpmn:outgoing>SequenceFlow_1id5mog</bpmn:outgoing>
    </bpmn:serviceTask>
    <bpmn:sequenceFlow id="SequenceFlow_12a8jo4" sourceRef="StartEvent_1" targetRef="Task_163mbh3" />
    <bpmn:endEvent id="EndEvent_06qupyv">
      <bpmn:incoming>SequenceFlow_1id5mog</bpmn:incoming>
    </bpmn:endEvent>
    <bpmn:sequenceFlow id="SequenceFlow_1id5mog" sourceRef="Task_163mbh3" targetRef="EndEvent_06qupyv" />
  </bpmn:process>
  <bpmndi:BPMNDiagram id="BPMNDiagram_1">
    <bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_1">
      <bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="StartEvent_1">
        <dc:Bounds x="173" y="102" width="36" height="36" />
        <bpmndi:BPMNLabel>
          <dc:Bounds x="156" y="145" width="70" height="14" />
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="ServiceTask_0wp3f5l_di" bpmnElement="Task_163mbh3">
        <dc:Bounds x="249" y="80" width="100" height="80" />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge id="SequenceFlow_12a8jo4_di" bpmnElement="SequenceFlow_12a8jo4">
        <di:waypoint x="209" y="120" />
        <di:waypoint x="249" y="120" />
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNShape id="EndEvent_06qupyv_di" bpmnElement="EndEvent_06qupyv">
        <dc:Bounds x="392" y="102" width="36" height="36" />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge id="SequenceFlow_1id5mog_di" bpmnElement="SequenceFlow_1id5mog">
        <di:waypoint x="349" y="120" />
        <di:waypoint x="392" y="120" />
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</bpmn:definitions>

Hi @matt!

Could you find a solution? If so, I would appreciate it if you share it with me.

Regards,
Natalia.

Hi @matt and @NataliaMG
I’m still looking for the answer to this…
if someone has found the solution please notify us.