How can I compare a taxonomy term with an expected value

Created on 4 January 2025, 17 days ago

Hi,

I think this module is exactly what I need to add some business logic workflows to a site I'm developing, but I'm really struggling with something that is probably very simple.

I have a taxonomy called 'Status' (field_status). I want to check when a node is updated and if the new value of status is a specific term, I want to update other fields on the node.

However, I cannot seem to figure out how to get the taxonomy term name. field_status (or [node:field_status]) holds the term ID and I can check against this, but if we expand the terms, there it will become difficult to 'hard code' the term IDs.

I can't seem to use the 'Entity: load via reference' to return the term name. Is the right 'task' to use?

How can I do a comparison of the taxonomy term name (e.g., [node:field_status:entity:name])?

Great module, but it's got me stumped at the moment.

💬 Support request
Status

Active

Version

2.1

Component

Documentation

Created by

🇬🇧United Kingdom gmak

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

Comments & Activities

  • Issue created by @gmak
  • 🇩🇪Germany jurgenhaas Gottmadingen

    What you're looking for are tokens. And you got to it towards the end of your issue description: the token [node:field_status:entity:name] in e.g. indeed giving you the name of the referenced entity, if the field field_status is an entity reference field and if the token node is available in the context where you're using that token.

    You can read more about Tokens in the ECA Guide.

    To do a comparison, you could e.g. use this condition: Compare two scalar values

    The first value could be your token [node:field_status:entity:name] and the second value could be the fixed name that you're looking for.

  • 🇬🇧United Kingdom gmak

    Hi Jurgen,

    Thank you for the help. It is working! I can now check that value of the taxonomy term. I hadn't tried the 'compare 2 scalar values'.

    I hope you might be able to help with the next step.

    If the value of the taxonomy term [node:field_status:entity:name] = 'X', I need to change the value of another taxonomy. How can I do this by passing a text value, say "New", to the taxonomy field [node:field_status_2] and have it update the node.

    The difficulty I am seeing is that the entity reference field [node:field_status_2] wants to be passed a taxonomy ID (tid) and not a text string.

    Is there a way to set a reference field value based on the string? (This would be like selecting the value from the select list in a form)

    Many thanks

  • 🇩🇪Germany jurgenhaas Gottmadingen

    The linked chapter about tokens in the ECA guide has an info block "Read-only vs. read-write tokens". The token like the one we used for comparison is read-only.

    If you want to change a field value in an entity, you have to load that entity (see https://ecaguide.org/plugins/eca/content/actions/eca_token_load_entity), then set one of its fields (see https://ecaguide.org/plugins/eca/content/actions/eca_set_field_value/) and then Dave that entity again.

    The library in the ECA guide has a lot of examples that are doing things like that. A lot of them also link to videos where you can watch how they got created.

  • 🇩🇪Germany jurgenhaas Gottmadingen
Production build 0.71.5 2024