2

This must be easy, but I just can't figure it out ...

My scenario is like so:

  • I have a content type with field A (title_field - text field) (that contains the title) and field B (field_tagged_as taxonomy reference).

  • I need to auto populate field B with the value from field A, after saving a new node or updating an existing node.

Is there a way to do this using the Rules module?

  • Merci for the accept Horia! Next question? Eg about Rules ...! – Pierre.Vriens Jul 13 '16 at 14:01
  • Thanks for the answer, Pierre! Does this rule also applies after updating a node (i.e: using VBO)? I will import it today! – Horia Rudan Jul 14 '16 at 6:21
  • I'm about sure it does apply for that also. If not just clone the rule (after you imported it) and adapt the event to make it fit your needs. Or first add some relevant event and then remove the event included in the imported rule here. To make it also work for using it with VBO, create a similar Rules Component (same conditions/actions), which you then use as "the operation" to be performed via VBO (check some of my other answers about rules, which also talk about VBO) – Pierre.Vriens Jul 14 '16 at 6:29
  • Well, it doesn't seam to work in may case, unfortunately. If I go and edit the rule, I can see that the "value" in the action is not imported. If I edit the action, at the value section it says: The new value to set for the specified data. Taxonomy term identifiers Specify a comma-separated list of identifiers of taxonomy term entities. Could this rule not work because field_tagged_as is a taxonomy reference field? – Horia Rudan Jul 14 '16 at 9:27
  • Can you have a look at my answer to this question and let me know if that helps? – Pierre.Vriens Jul 14 '16 at 9:54
0

Here is a rule (in Rules export format) that does exactly what your question is about:

{ "rules_auto_populate_fields" : {
    "LABEL" : "Auto populate fields",
    "PLUGIN" : "reaction rule",
    "ACTIVE" : false,
    "OWNER" : "rules",
    "REQUIRES" : [ "rules" ],
    "ON" : { "node_presave" : [] },
    "IF" : [
      { "entity_has_field" : { "entity" : [ "node" ], "field" : "title_field" } },
      { "entity_has_field" : { "entity" : [ "node" ], "field" : "field_tagged_as" } }
    ],
    "DO" : [
      { "data_set" : {
          "data" : [ "node:field-tagged-as" ],
          "value" : "[node:title-field]"
        }
      }
    ]
  }
}

Notice the "entity has field" conditions, for both fields. Those conditions will make the fields available in the Rules Action ... (so that you can reference field A and set the value of field B).

If you have the Rules UI enabled, and if the machine names of your fields are indeed "title_field" (for field A) and "field_tagged_as" (for field B), you should be able to just import this rule in your own site. If you're using other machine names, just adapt the machine names prior to importing this rule (and apply similar changes in the fields mentioned in the Rules Action).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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