How to programmatically set Webform field value with custom submit? I try to update an hidden field value with my custom submit, but it doesn't work, my new value are not saved.

With :  $form_state-&gt;setValue('token_uid', $token_uid);

  function MODULE_form_alter(&amp;$form, FormStateInterface $form_state, $form_id) {

    if ($form_id == 'webform_submission_creation_compte_add_form' || $form_id == 'webform_submission_creation_compte_test_form') {

      foreach (array_keys($form['actions']) as $action) {
        //attention en multi step : wizard_next
        if ($action != 'wizard_next' &amp;&amp; $action != 'preview' &amp;&amp; isset($form['actions'][$action]['#type']) &amp;&amp; $form['actions'][$action]['#type'] === 'submit') {
          $form['actions'][$action]['#submit'][] = '_MODULE_creation_compte_submit';
        }
      }
      if (isset($form['#validate'])) {
        $form['#validate'][]  =  '_MODULE_creation_compte_validate';
      }
    }
  }


My custom submit function : 

function _MODULE_creation_compte_submit(array &amp;$form, FormStateInterface $form_state) {
    global $base_url;
    $data               = array();
    $user_id_created    = null;

    //Info account
    $account_name       = $form_state-&gt;getValue('nom');
    $account_username   = $form_state-&gt;getValue('username');
    $account_first_name = $form_state-&gt;getValue('prenom');
    $account_mail       = $form_state-&gt;getValue('email');
    $account_password   = $form_state-&gt;getValue('mot_de_passe');
    $account_phone      = $form_state-&gt;getValue('telephone');


    if (!empty($account_username) &amp;&amp; !empty($account_password) &amp;&amp; !empty($account_mail)) {

        $account_username   = strtolower(str_replace(' ', '', $account_username)).'_'.rand(0,1000);

        $user_created       = User::create([
          'name'                  =&gt; $account_username,
          'pass'                  =&gt; $account_password,
          'mail'                  =&gt; $account_mail,
          'field_user_nom'        =&gt; $account_name,
          'field_user_prenom'     =&gt; $account_first_name,
          'field_user_telephone'  =&gt; $account_phone['phone'],
          'status'                =&gt; 0,
          'init'                  =&gt; $account_mail,
          'created'               =&gt; time(),
          'changed'               =&gt; time(),
          'login'                 =&gt; 0,
          'access'                =&gt; 0,
        ]);
        $user_created-&gt;save();
        $user_id_created = $user_created-&gt;id();
        $token_uid       =  $base_url . '/user/' . $user_id_created;

       //==&gt; Value is not saved after submit
        $form_state-&gt;setValue('token_uid', $token_uid);

    } 
}
The solution with hook_ENTITY_TYPE_presave :

use Drupal\webform\WebformSubmissionInterface;

 function MODULE_webform_submission_presave(WebformSubmissionInterface $webform_submission){
    global $base_url;
    $user_id_created    = null;

    //Info account
    $account_name       = $webform_submission-&gt;getElementData('nom');
    $account_username   = $webform_submission-&gt;getElementData('username');
    $account_first_name = $webform_submission-&gt;getElementData('prenom');
    $account_mail       = $webform_submission-&gt;getElementData('email');
    $account_password   = $webform_submission-&gt;getElementData('mot_de_passe');
    $account_phone      = $webform_submission-&gt;getElementData('telephone');

    if (!empty($account_username) &amp;&amp; !empty($account_password) &amp;&amp; !empty($account_mail)) {

      $account_username   = strtolower(str_replace(' ', '', $account_username)).'_'.rand(0,1000);

      $user_created       = User::create([
        'name'                  =&gt; $account_username,
        'pass'                  =&gt; $account_password,
        'mail'                  =&gt; $account_mail,
        'field_user_nom'        =&gt; $account_name,
        'field_user_prenom'     =&gt; $account_first_name,
        'field_user_telephone'  =&gt; $account_phone['phone'],
        'status'                =&gt; 0,
        'init'                  =&gt; $account_mail,
        'created'               =&gt; time(),
        'changed'               =&gt; time(),
        'login'                 =&gt; 0,
        'access'                =&gt; 0,
      ]);
      $user_created-&gt;save();
      $user_id_created = $user_created-&gt;id();
      $token_uid       =  $base_url .'/user/' . $user_id_created;
      $webform_submission-&gt;setElementData('token_uid', $token_uid);
    }
  }