I have created a rule to add terms to an existing Term Field. The rule fires correctly, it's adding the Term to the Field. However, it's overwriting all the existing terms within the field.
I have tried to follow the steps from this similar question as well as this Tutorial, however, it's still a no go for me.
More details about my setup:
- Vocabulary: Emails (machine name:
emails
) - Email Field: Email Field (machine_name:
field_primary_email
), which is a single value field. - Term Reference: Email Term Reference (machine_name:
field_email_term_reference
)
The requirement is to display Email communication basis of the Email address present in the node [ Contact Content Type].
I have a rule which picks up the primary email & creates a taxonomy term from it. The second rule, assigns the relevant terms basis of the email present in the node. The email address in the node may change, however, the terms are to remain to display the past communication. When the new email is updated in the node, the first rule creates a new taxonomy term basis of the updated email address. When the new term is created, the second rule picks up the term & assigns it to the Term reference field along with the existing ones. It is not to overwrite the terms already present in the field. Basis of the terms present in the node, I can display the email communication.
My rule I created so far (in Rules export format):
{ "rules_update_email_term_reference" : {
"LABEL" : "Update Email Term Reference",
"PLUGIN" : "reaction rule",
"OWNER" : "rules",
"REQUIRES" : [ "rules" ],
"ON" : { "node_view" : [] },
"IF" : [
{ "entity_is_of_bundle" : {
"entity" : [ "node" ],
"type" : "node",
"bundle" : { "value" : { "candidates" : "candidates", "clients" : "clients" } }
}
},
{ "entity_has_field" : { "entity" : [ "node" ], "field" : "field_email_term_reference" } }
],
"DO" : [
{ "LOOP" : {
"USING" : { "list" : [ "node:field-email-term-reference" ] },
"ITEM" : { "current_term" : "Current Term" },
"DO" : []
}
},
{ "entity_query" : {
"USING" : {
"type" : "taxonomy_term",
"property" : "name",
"value" : [ "node:field-primary-email" ]
},
"PROVIDE" : { "entity_fetched" : { "entity_fetched" : "Fetched entity" } }
}
},
{ "list_add" : {
"list" : [ "node:field-email-term-reference" ],
"item" : [ "entity-fetched:0" ],
"unique" : "1"
}
}
]
} }