2

I have a content type that has 3 term reference fields:

  • Field A (required), which contains a single tag.
  • Field B (required), which contains a single tag.
  • Field C (not required), which contains a single tag.

The tags from those 3 fields all related to the same taxonomy.

When creating or updating a node, values are entered for field A and B. I want to have a rule ((using the Rules module) with some Rules Action to set a data value for field C, equal to the concatenation of the value entered for field A and B. But "set a data value" only sets one value.

What can I do to set multiple values?

Some more screenprints to explain all this:

enter image description here

enter image description here

enter image description here

And here is my current Rule I'm trying to get to work:

{ "rules_juhe_xieru" : {
    "LABEL" : "\u805a\u5408\u5206\u7c7b\u81ea\u52a8\u5199\u5165",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules" ],
    "ON" : { "node_insert--mfpf" : { "bundle" : "mfpf" } },
    "DO" : [
      { "data_set" : { "data" : [ "node:field-juhe-fenlei" ], "value" : [ "node:field-diqu" ] } }
    ]
  }
}
2
  • Comments have been removed. Please don't use them for extended discussion. Add the relevant bit of information to the question, when necessary. As @Pierre.Vriens said, be sure to add all the necessary information in the question, before to post it. Q&A sites are one-way sites: You ask a question, and you get answers. You don't change the question basing on the received answers, and answers should not be changed because you changed the question. Be sure it's clear from the question what you want to achieve and what your question is, then post it.
    – avpaderno
    Commented Dec 5, 2016 at 8:26
  • I've answered this in your new thread. drupal.stackexchange.com/a/222189/53677 Commented Dec 5, 2016 at 15:57

2 Answers 2

3

Your question is not clear (enough), at least not yet, so I'll try with 2 variations ...

Field C is about Single values

It think your rule needs at least 2 corrections:

  • Add a Rules condition like "entity has field", for each "token" that you want to use in any rules Action, but which is not (yet) showing up to actually select it in some Rules Action.
  • When using a Rules Action like "Set a data value", you can indeed only set such value for 1 variable. However if you want to "Set a data value" for another variable, just add a 2nd Rules Action to do so for that other variable.

Field C is about Multiple values

Maybe your question is rather something like so:

If this Rules Event happens, then I want to add the node reference in field A to field C, and I also want to add the node reference in field B to field C (and field C is a multi value node reference field".

In this case, using "Set a data value" is completely wrong. Instead you need to use an action like "Add item to a list". I.e.:

  • Rules Action 1 is to add A to the list C (possibly you also need a Rules Condition like "Entity has field" (for A)).
  • Rules Action 2 is to add B to the list C (possibly you also need a Rules Condition like "Entity has field" (for B)).

Refer to my answer to "How to set multiple values to an unlimited Term Refence field with Rules" for way more details about "Add item to a list".

Recommendations to improve the alternative answer

Now (after about a day of extra questions/comments to the question from No Sssweat and myself), it finally became clear what the real question was ...

Here is a variation of the Rule in the alternative answer:

{ "rules_improved_combination_of_taxonomy_terms" : {
    "LABEL" : "Improved combination of taxonomy terms",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules" ],
    "ON" : { "node_view--article" : { "bundle" : "article" } },
    "DO" : [
      { "drupal_message" : { "message" : "[node:field-a][node:field-b]" } },
      { "variable_add" : {
          "USING" : { "type" : "text", "value" : "[node:field-a][node:field-b]" },
          "PROVIDE" : { "variable_added" : { "variable_added" : "Added variable" } }
        }
      },
      { "entity_create" : {
          "USING" : {
            "type" : "taxonomy_term",
            "param_name" : "[variable-added:value]",
            "param_vocabulary" : "tags"
          },
          "PROVIDE" : { "entity_created" : { "entity_created" : "Created entity" } }
        }
      },
      { "entity_save" : { "data" : [ "entity-created" ], "immediate" : "1" } },
      { "data_set" : { "data" : [ "node:field-c" ], "value" : [ "entity-created" ] } },
      { "entity_save" : { "data" : [ "node:field-c" ], "immediate" : "1" } }
    ]
  }
}

These are the extra refinements needed to make it work:

  • Add an action to save an entity (twice), because since you used Rules Event to just wake up after viewing a node, you need to remind the Rules module to also save what you've been creating/updating.
  • Remove the Fetch entity (no need for that).

By the way, the clue to debug the rule in the other answer can be found if you turn on rules logging: you'll see that the fetch entity didn't return any results, so blank, which is also what got saved in field C ...

Demo:

Field A: Bonjour
Field B: World
Field C: BonjourWorld

At least that's what happened in my tests. If I change A to Hello (or No), B to Liu (or Sssweat), then C gets updated to HelloLiu (or NoSssweat) ...

Be Aware: I can think of some further improvements of all this, but for now I consider this rule as "Make it right before you make it better" ... try it in your own setup to confirm it does answer the quetion (but please don't post enhancement requests via extra comments, instead post a new question if needed).

Disclaimer: I don't have a clue what those non-English "pictures" are (I bet they are characters in your native language ...).

1
  • Comments have been removed. Please don't use them for extended discussion.
    – avpaderno
    Commented Dec 5, 2016 at 8:16
1

Something like this is in the right path, I just can't get the field C to set to the ab tax term that gets created by Rules though.

enter image description here

{ "rules_combine_taxonomy_terms" : {
    "LABEL" : "combine taxonomy terms",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules" ],
    "ON" : { "node_view--article" : { "bundle" : "article" } },
    "DO" : [
      { "drupal_message" : { "message" : "[node:field-a][node:field-b]" } },
      { "variable_add" : {
          "USING" : { "type" : "text", "value" : "[node:field-a][node:field-b]" },
          "PROVIDE" : { "variable_added" : { "variable_added" : "Added variable" } }
        }
      },
      { "entity_create" : {
          "USING" : {
            "type" : "taxonomy_term",
            "param_name" : "[variable-added:value]",
            "param_vocabulary" : "tags"
          },
          "PROVIDE" : { "entity_created" : { "entity_created" : "Created entity" } }
        }
      },
      { "entity_fetch" : {
          "USING" : { "type" : "taxonomy_term", "id" : [ "entity-created:tid" ] },
          "PROVIDE" : { "entity_fetched" : { "entity_fetched" : "Fetched entity" } }
        }
      },
      { "data_set" : { "data" : [ "node:field-c" ], "value" : [ "entity-fetched" ] } }
    ]
  }
}

enter image description here

As you can see the "helloworld" gets created, but somehow we would have to check in Rules if "helloworld" term name already exists using Conditional Rules but I am not yet sure if this is possible, haven't tried.

You would do get entity by property and pass the variable as the name I suppose, but what will that return? NULL or 0?

NOTE: This rule still comes up short, as mentioned in the begining, I still see

enter image description here

1
  • Comments have been removed. Please don't use them for extended or tangential discussion.
    – avpaderno
    Commented Dec 5, 2016 at 8:18

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.