1

I have a field on a user profile called field_certified_tap. When this is equal to 1 or true on user update/create, I want to send an email.

Currently, I do not see this field in the Condition->Entity Has Value->[data select].

I am using the 3x-dev version of Rules and the 1x version of token.

Rules token dropdown

What am I doing wrong? Is there currently a way to accomplish this with Rules UI or should I make my own Rule or implement in the user save hook?

Thanks!

1 Answer 1

0

In your image, you are configuring the "Entity" parameter of the "Entity has field" condition. That parameter should be set to just "user" in the data selector - it would be wrong to specify a field here since it is calling for the entity that you want to check.

The SECOND parameter should be "Field", and it is there that you would want to enter "field_certified_tap" using direct input (not data selector).

Note that the "Entity has field" condition cannot be used to check the value of the field - that has to be done in a separate "Data comparison" condition.

But you are right that even when you properly configure the "Entity has field" condition, your custom field does not show up in the data selector for subsequent actions. I'm not sure why, but there's an open bug report for that in the Rules issue queue: "Entity has field" doesn't actually give access to the field

Instead, use the "Entity is of bundle" condition to get access to the field. Here's an example using a boolean field called "field_certified_tap" which I added to the user entity. If you import this Rule and examine it in your UI you will see that after adding the "Entity is of bundle" condition to the rule, the data selector in the "Data comparison" condition and the "Show a system message" action DOES now give you an option of "user.field_certified_tap". You can then add a "Data comparison" condition to show the message only when field_certified_tap is true.

I'm using "Show a system message" here because it's much easier to use for debugging than "Send mail". You should use this action to test the tokens you plan to use for your email, then when you are sure you have the values you need you can add a "Send mail" action.

langcode: en
status: true
dependencies: {  }
id: access_certified_tap_field
label: 'Access user certified tap field'
events:
  -
    event_name: 'rules_entity_update:user'
description: ''
tags: {  }
config_version: '3'
expression:
  id: rules_rule
  uuid: 137a6a57-2d1a-467d-80e6-68091de5eb11
  conditions:
    id: rules_and
    uuid: 098bb2b1-3e95-4efa-9328-07b651591e63
    conditions:
      -
        id: rules_condition
        uuid: 3b23a038-ac0c-4461-b14b-6db518c3261a
        context_values:
          type: user
          bundle: user
        context_mapping:
          entity: user
        context_processors:
          type:
            rules_tokens: {  }
          bundle:
            rules_tokens: {  }
        provides_mapping: {  }
        condition_id: rules_entity_is_of_bundle
        negate: false
      -
        id: rules_condition
        uuid: fbcdef7b-9681-47a2-bcac-94d49c86d7fa
        context_values:
          data: '{{ user.field_certified_tap }}'
          operation: '=='
          value: '1'
        context_mapping: {  }
        context_processors:
          data:
            rules_tokens: {  }
          operation:
            rules_tokens: {  }
          value:
            rules_tokens: {  }
        provides_mapping: {  }
        condition_id: rules_data_comparison
        negate: false
  actions:
    id: rules_action_set
    uuid: d6d904a0-007a-4f7f-97be-ac7c1f64edd2
    actions:
      -
        id: rules_action
        uuid: c5d31406-7355-4d91-b623-2c55dc3d57cb
        context_values:
          message: 'User is certifiable!'
          type: warning
          repeat: false
        context_mapping: {  }
        context_processors:
          message:
            rules_tokens: {  }
          type:
            rules_tokens: {  }
          repeat:
            rules_tokens: {  }
        provides_mapping: {  }
        action_id: rules_system_message

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.