How to set field value in custom webform submit handler? In a custom submit handler, I want to set a field value for a text field (my_field_machinename) in my webform. The handler is getting called correctly, but the value is not getting stored. What do I have to change in the code below to make it work?
I know I could use the presave hook, but I would prefer to make the alteration within the submit handler.
class CustomHandler extends WebformHandlerBase {

  use StringTranslationTrait;

  /**
   * {@inheritdoc}
   */
  public function submitForm(array &amp;$form, FormStateInterface $form_state, WebformSubmissionInterface $webform_submission) {
    $this-&gt;submitMyFieldData($form_state);
  }

  /**
   * Set my field values
   */
  private function submitMyFieldData(FormStateInterface $formState) {
    $formState-&gt;setValue('my_field_machinename', [['value' =&gt; '123']]); // Does not work

  }

}
Only now did I realize there is not only a submitForm method but also a presave method. I therefore changed my code as follows which is woking fine for me:
class CustomHandler extends WebformHandlerBase {

  use StringTranslationTrait;


  /**
   * {@inheritdoc}
   */
  public function preSave(WebformSubmissionInterface $webform_submission) {
    $this-&gt;submitMyFieldData($webform_submission);
  }


  /**
   * @param $webform_submission
   *
   * Manipulate data.
   *
   */
  private function submitMyFieldData($webform_submission) {
    $data = $webform_submission-&gt;getData();

    // to get a value from a form field
    $form_value = $data['my_field_machinename'];

    // to set the value of a form field
    $data['my_field_machinename'] = $form_value + 1;

    $webform_submission-&gt;setData($data);

  }