3

I'm using the Rules Action Set Data Value to set a taxonomy term for a specific user (uid= 75). The tag field exists in the user entity, and is set to "Unlimited".

There's nothing complicated about the rule, which looks like so:

{ "rules_invited_user" : {
    "LABEL" : "Invited user",
    "PLUGIN" : "reaction rule",
    "REQUIRES" : [ "rules" ],
    "ON" : [ "user_presave" ],
    "IF" : [ { "data_is" : { "data" : [ "account:uid" ], "value" : "75" } } ],
    "DO" : [
      { "data_set" : { "data" : [ "account:field-user-tag" ], "value" : "27608" } }
    ]
  }
}

I can set the term, but if there's another term set already for that user, it's overwritten.

How can I set a new term without overwriting an existing one?

2

The Rules Action Set a data value that your Rule uses, can only set 1 value, while you're trying to update something that is a list (or to use your own words: "... set a new term without overwriting an existing one").

So try to replace your Rules Action (ie with the data_set) with an action "Add an item to a list". When doing so, you probably also want to set "ENFORCE UNIQUENESS" to true, so that you "only add the item to the list if it is not yet contained". Even though for your case it may not make a difference, IMO that is a kind of safety-belt when using this action.

For way more details about this, refer to "How to set multiple values to an unlimited Term Refence field with Rules". While reviewing this, also pay attention to the "Fetch entity by ID" (within the Rules loop): I wouldn't be surprised if you'd also need to add a similar "Fetch entity by ID".

Ps: I'm assuming this question is about D7 ...

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.