Form field validation start event

I have a custom front-end that shows the start form of all configured form fields of a specific process definition in a Start Event. From here you can start a process.

I’m trying to get validation to work when starting a process. Similliar to submitting a task form. For a Task there’s a method in the FormService called submitTaskForm, which eventually checks if there are any validators configured, if so it will start validating them.

Now I do the same for starting a process. I’m using the submitStartForm method, however this never checks if there are any validators configured (max length, required, etc) on the form fields and so makes it possible to start a process without the needed variables.

Is there a way to get the submitStartForm to check if any validators are configured? Or am I using the wrong method?

@kvarbyte can you share a bpmn file with this occurring?

@StephenOTT

Attached a test model. On the start event under “Forms” in the Modeler i"ve added a form field with validation.

The problem is when I use the submitStartForm method from the FormService java class it still starts the process instance without respecting the validation. Code wise I can see that it’s basically just starting a process instance. See here: camunda-bpm-platform/SubmitStartFormCmd.java at master · camunda/camunda-bpm-platform · GitHub

However when I use this for a Task it does check the validation properties. Once again I use the FormService and call submitTaskForm method. Which eventually ends up here: camunda-bpm-platform/SubmitTaskFormCmd.java at master · camunda/camunda-bpm-platform · GitHub
(It eventually calls the TaskFormHandler which checks validation and such)

So I kinda expected that the submitStartForm method would do the same, but it doesn’t .

test_diagram.bpmn (3.5 KB)

Can you test this against the rest API. The rest API respects calling the validations on a start event and on user tasks. So there is a issue with the commands you are calling. Test against rest API and see if it works as expected.

I tested using the process-definition/key//start endpoint. With the following payload in regards to my previous process:
{
“variables”: {
      “first_name”: { “value”: “a”, “type”: “String”}
     }
}

This still starts the process and doesn’t respect the validations configured on the “first_name” form field.

Ya so your issue is you are using the wrong start command

when you have form validation constraints you need to use the /submit-form endpoint

localhost:8080/engine-rest/process-definition/key/minlength/submit-form

{
    "variables": {
        "first_name": {
            "value": "a",
            "type": "String"
        },
        "priority": {
            "value": 22,
            "type": "Integer"
        }
    }
}
{
    "type": "RestException",
    "message": "Cannot instantiate process definition minlength:3:9fdfd834-43c7-11e8-91b5-0242ac130002: Invalid value submitted for form field 'first_name': validation of minlength(2) failed."
}

which uses your validation constraints.

you need to be using the Form Service when using the Java API:

Start with Form Submission: https://docs.camunda.org/javadoc/camunda-bpm-platform/7.8/org/camunda/bpm/engine/FormService.html#submitStartForm(java.lang.String,%20java.util.Map)

User Task Submission: https://docs.camunda.org/javadoc/camunda-bpm-platform/7.8/org/camunda/bpm/engine/FormService.html#submitTaskForm(java.lang.String,%20java.util.Map)

you can also take a look at: Form Server Validations: Generic Form Validator using Javascript which will give you more control over validations

For ref:

https://docs.camunda.org/manual/7.8/reference/rest/process-definition/post-submit-form/

My bad I should have used that endpoint. And yes there it works and validation is checked.

Since I have my own REST API I can’t use this endpoint. However I did look at the ProcessDefinitionResourceImpl class in Camunda Rest core. I debugged my own code a bit compared to what’s done there and eventually it was because the variable mapping. I fixed it so it makes use of the VariableValueDto and everything works now.

Thanks for the help