Compare webform submission value with custom user field

Created on 4 May 2023, over 1 year ago
Updated 30 June 2023, over 1 year ago

Problem/Motivation

Not sure if this is a bug or I'm just doing something wrong. I'm trying to create a model that adds a role to the logged in user whenever they submit a particular Webform, and when a string comparison condition between the webform submission value and a user custom field is true.

The model works as expected when I don't include the condition, i.e. when the user submits the form, the role is added to that user's account. However, the same action does not succeed when I add the condition.

I have tried two condition types without success:

Entity: compare field value
Form field: compare submitted value

I'm trying to check for a match of the following two field values - [webform_submission:values:answer] and [current-user:field_security_answer]. I've also tried two different comparison operators - "equals" and "contains".

Any idea how to make this work?

πŸ’¬ Support request
Status

Fixed

Version

1.2

Component

Code

Created by

πŸ‡ΈπŸ‡¦Saudi Arabia ishore

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @ishore
  • πŸ‡©πŸ‡ͺGermany mxh Offenburg
  • πŸ‡©πŸ‡ͺGermany mxh Offenburg
  • πŸ‡©πŸ‡ͺGermany jurgenhaas Gottmadingen

    This depends upon the event you're starting your model with. As you're using the webform_submission token, this can only work after that entity has been stored to the database. So, the event needs to be Insert content entity for that content type.

    If you wanted to start your model with an earlier event, you could use the eca_webform module β†’ which provides access to all the events from the webform module. For details, see https://ecaguide.org/plugins/eca/webform/ where you can find the full list of events in the left navigation bar. All those events provide some tokens automatically, that let you interact with the webform process. Unfortunately, those tokens are not documentd in the ECA Guide yet, but you can find the list of tokens in code when you look into the \Drupal\eca_webform\EventSubscriber\EcaWebform class.

  • πŸ‡ΈπŸ‡¦Saudi Arabia ishore

    Still doesn't work for me unfortunately. I change the event to be "Insert content entity" and, without adding the condition, the model works as expected, adding the user to the role. But as soon as I add the condition, it fails - "Not asserting condition".

  • πŸ‡©πŸ‡ͺGermany jurgenhaas Gottmadingen

    Have you tried the debugging techniques described at https://ecaguide.org/eca/debugging/ already? They give you an idea about the available tokens and what value they have.

    In addition to that, you can use the action Display a message to the user action to print the value of the tokens you're using on screen, so that you can verify that your token syntax is correct.

    Note, when you're using the "Insert entity" event, your webform submission entity is available as a token with the name entity. Therefore, you may want to use [entity:values:answer] or the likes, if those are valid tokens for webform submissions. The token browser will show you all the available token details for each entity type and others.

  • πŸ‡ΈπŸ‡¦Saudi Arabia ishore

    I'm experiencing such unpredictable behaviour that I'm not sure what to say at this point. I set the "Display a message to the user" to print the value of both tokens, and on submitting the form, they are shown to be identical.

    However, the role was not added to the account. But now, even after removing the condition, the role is still not added to the account when the form is submitted, which is different behaviour from before. Very confused.

  • πŸ‡©πŸ‡ͺGermany jurgenhaas Gottmadingen

    That's not a surprise, because the user who submits the form has most likely not sufficient permissions to add a role to themselves. That's why that action is not permitted and will not be executed.

    In such cases, we can only really recommend to use the linked debugging techniques, because there you can see all those details. If nothing else helps, you should then build the simplest possible model which let's you reproduce the problem in a fresh Drupal installation and upload that model to the issue so that it can be reviewed.

  • πŸ‡ΈπŸ‡¦Saudi Arabia ishore

    I think my confusion has been at least partly cause by the fact that it seems to be impossible to completely remove a condition in BPMN.iO - removing the template doesn't stop the condition from being acted upon. The debug logs showed that the condition was still being actioned after I removed the template.

    The fact that I know from the messages that my two tokens are identical would lead me to assume that my issue is with the condition, and I don't think I'm picking the correct condition template to compare the two tokens.

    Anyway, I am pursuing a solution using a Webform Handler instead, and will re-visit ECA for some other actions later.

  • πŸ‡©πŸ‡ͺGermany jurgenhaas Gottmadingen

    it seems to be impossible to completely remove a condition in BPMN.iO - removing the template doesn't stop the condition from being acted upon

    This is a known issue for the upstream bpmn.io library that's being used for the UI. Unfortunately, we have to wait until it's being fixed by their maintainers. In the meantime, deleting a link and adding a fresh one does the trick in this case.

  • Status changed to Fixed over 1 year ago
  • πŸ‡©πŸ‡ͺGermany jurgenhaas Gottmadingen

    If I'm not mistaken, sounds like we can mark this one as fixed. Please revert this, if not.

  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024