How to check variables from form in startEvent listener?

Hello.
There was a problem. In the startEvent I have assigned a listener which should check the variables and not start process if the variables are not true.
If I start the process through rest and pass variables in the body, then in the listener with the command
delegateExecution.getVariable (“contract”) I get the contract number and check it.

If I start the process through Camunda TaskList, I enter the contract number and click start then in the listener with the command
delegateExecution.getVariable (“contract”) getting null.

How do I get the value of a variable submitted through a TaskList form?

You need to start the process instance asynchronously. Enabling asynchronous continuations using property camunda:asyncBefore="true" will provide save point and it will persist the form variables. So that you can access those form variables from Listeners/Delegates.

<bpmn:startEvent id="Event_1j8phgu" name="E-Commerce Login" camunda:asyncBefore="true">
      <bpmn:outgoing>Flow_0zjpes6</bpmn:outgoing>
</bpmn:startEvent>

image


Refer the below post:

if I start the process through rest, then I can get access to the form variables. if through the form into the tasklist, then no.
this is strange! my task is this: you need to check the input data in the form, and if they are not valid, then do not start the process and issue a notification. I did this check in the startEvent in the listener on start… what is the best way to make the check?

@Oleg_Kiselyov, Followed by my previous post, you can add ExecutionListener to StartEvent and using FormsService you can access the form variables and validate, if validation fails you can throw exception or BpmnError.

@Component("startFormValidationListener")
public class StartFormValidationListener implements ExecutionListener {

  @Autowired
  private FormService formService;

  @Override
  public void notify(DelegateExecution execution) throws Exception {
    VariableMap variableMap = formService
                 .getStartFormVariables(execution.getProcessDefinitionId());
    String orderId = variableMap.getValueTyped("orderId");
    if (!StringUtils.hasText(orderId)) {
      throw new BpmnError("ORD-404", "Order not found");
    }

    Double orderPrice = variableMap.getValueTyped("orderPrice");
    if (orderPrice.doubleValue() < 1000.00) {
      throw new BpmnError("ORD-400", "Order price should not be < 1000.00");
    }
  } 
}  

I already tried something like this … it works through rest, there is no TaskList through the form … screenshots below
but if you look at the executor, there are variables in startContext. How can I get them out of startContext?