Setting a field value fails in the case of a Cron event

Created on 7 April 2025, 11 days ago

I've been struggling with this for a while. Setting the field value is successful in other cases, but not if the event is a Cron run. Loading the field value is also successful, as it displays the field value afterwards. But setting the Field value is failing. I simply can't figure out why, I've tried every variation, changed the token entry format, to see if it needs something different in this case. I've also specified other settings, etc. The error message in the log is "access denied".

I've been trying to solve this for days, but I can't. In principle, I did everything right.

If anyone knows the solution, thanks in advance!

πŸ’¬ Support request
Status

Active

Version

2.1

Component

Miscellaneous

Created by

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

Comments & Activities

  • Issue created by @tetatu
  • πŸ‡©πŸ‡ͺGermany jurgenhaas Gottmadingen

    If you run cron on a Drupal site, the PHP process executes in the context of an anonymous user. And those don't have the permission to change entity field, normally. That's why you get an access denied message. You can use the switch user action to escalate privileges of your ECA model.

  • But I gave Admin 1 permissions at the beginning of the process.
    In the original post, I included the model and the SVG image of the model, so you can see that I did it this way and gave permission.

    https://ecaguide.org/plugins/eca/user/actions/eca_switch_account/

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

    In the "Entity: set field value" action you didn't specify for which entity you want to set the field value.

  • Solved.
    So, if it is "Event: Cron", "Action: Entity Load", then "Entity: set field value", then when setting "Action: Entity Load", the following fields cannot be left blank, but the field token must be entered in both: "Name of token" and in the "Entity" field.

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

    The event cron doesn't automatically provide any tokens.

    When you use the action "Load entity", you store the loaded entity in a token.

    Then, when using the "Set field value" action, you need to use the token name that holds your entity in the entity field.

    That's pretty much exactly what the description in the config forms tells as well. And there is a full chapter about tokens in the ECA Guide.

  • I browsed the https://ecaguide.org/ page a lot, but I didn't always find a detailed description that would have helped, but it's probably enough for a more experienced Drupal developer. What is required in the configuration form is not always clear. Obviously, you have to get used to it after the Rules module, where the module already provided the values ​​to be set in a drop-down list, but in ECA you have to enter them manually and the form of entering tokens and more, it's a bit confusing.
    I'll go through the section about Tokens in the description again.
    Thank you!

  • πŸ‡©πŸ‡ͺGermany jurgenhaas Gottmadingen
Production build 0.71.5 2024