Drupal - How to change a field value with a Rules Action?

You first need to add a condition to check if the field exist on that node, only then it is available to the actions. There is a specific condition to do this.


Using the "Entity has field" (or "content is of type") condition will make the fields become available with data selection in the Action "Set a data value".


Not to contradict both prior answers, but IMO they are both missing (ignoring?) a crucial part of the question, which is "...I created an Action Set...". True, part of the solution is, pretty sure, "Entity has field" (as in the answer from jcarballo). But, by design of a Rules Action Set, you cannot include any Rules Condition in it. Therefor, either of the following is needed to complete the answer to this question:

  • Also use the Conditional rules module, which does allow to include conditions in Rules Actions. For an example of a rule (in Rules export format) in which this technique is used, have a look at the (last) rule in my answer to "How to include only an updated custom field in an email created using Rules?".
  • Replace the entire Action Set with a Rules Set, in which you can specify Rules Conditions and Rules Actions.

With the above in mind, you should be able to create a Rules Action like (e.g.) "Set a data value" for your field, if you also add a Rules condition Entity has field (related to the field for which you want to set a value). And make sure to add that Entity has field condition BEFORE other Rules Conditions in which you might want to refer to this field (if you have any such conditions in your rule).

That's also what is mentioned in the Rules UI, e.g. when you're adding a "data comparison" condition: somewhere it says "The data selector helps you drill down into the data available to Rules. To make entity fields appear in the data selector, you may have to use the condition 'entity has field' (or 'content is of type')".

For a video tutorial that illustrates the importance of this Entity has field condition, refer to Data types and data selection, especially what is shown between about 13:30 and 17:30 in it.