How do I fill the authors name in a term reference field? Content type stock contains the term reference field field_producer. What is the rule for Rules in order to fill this field with the node author name on creation?

In detail

The form looks like:

-- Content type Stock (stock)

---- field Producer (field_producer); of field type Term reference; of widget Autocomplete term widget (tagging); number of values: 1; Vocabulary: Producer

The goal is:

When a user creates a node of the type Stock, his user name should automatically be filled/(pre-)populated in the field Producer.

Why Rules: 

Since tokens aren't working for the autocomplete term reference field and a text field isn't available, rules might be a workaround. I've tried Prepopulate, Entityreference prepopulate, and other modules, but none of them supported the aim. 

Where I am struggling with Rules:


Event: After saving new content, Restrict by type Stock
Condition: Entity has field, Data selector node:field-producer, Field Value field_producer
Action: Set a data value, Data (to be modified) node:field-producer, Value (to set for the specified data): HERE REMAINS THE PROBLEM. I can't choose node:author or other tokens that display the user name. I get the restriction: "Data types: Select data of the type Taxonomy term."


That's why I am not able to successfully create this rule. 

What am I doing wrong? How should this rule look like?
... I can't choose node:author or other tokens that display the user name. I get the restriction: "Data types: Select data of the type Taxonomy term."


1. Switch to the direct input mode

You should click the Switch to the direct input mode button (near the bottom left), which looks like this:



After clicking that button, it will bring up a selection list of the available terms (= possible values) that you can use in your taxonomy field.

2. Example

Consider this example, in Rules Export format, of a rule (actually a Rules Component, but the idea is the same) to illustrate how such Rules Action to "Set a data value" should look like and which will set the value of the term reference field field_sample_tags to term id = 31:

{ "rules_replace_a_term_field_by_another_term_field" : {
    "LABEL" : "Replace a term field by another term field",
    "PLUGIN" : "rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules" ],
    "USES VARIABLES" : { "node" : { "label" : "Node", "type" : "node" } },
    "IF" : [
      { "entity_has_field" : { "entity" : [ "node" ], "field" : "field_sample_tags" } },
      { "entity_has_field" : { "entity" : [ "node" ], "field" : "field_demo_tags" } },
      { "data_is" : { "data" : [ "node:field-demo-tags" ], "value" : "1" } }
    ],
    "DO" : [
      { "data_set" : { "data" : [ "node:field-sample-tags" ], "value" : "31" } },
      { "drupal_message" : { "message" : "Term updated in node with id = [node:nid]" } }
    ]
  }
}


Some more details to explain the above prototype:


It uses a node as a parameter (to execute the Rules Component).
These are the Rules Conditions:


check if the entity (= node) has a field field_sample_tags.
check if the entity (= node) has a field field_demo_tags.
check if the value of the field field_demo_tags corresponds to the term we want to replace (in this example, the term has id = 1).

These are the Rules Actions:


Set the value of field field_sample_tags equal to the term with term id = 31 (which is the term in the vocabulary for which we want to add the term reference).
Display a message on the site (only used for demo / testing).



3. Improvement - Pick the existing term that fits

Your question doesn't say "How to pick the appropriate term (i.e. its term id) to be used to perform the 'Set a data value' for a given node author (how can you derive that term id from the data about the node author)?".

If you only have a few node authors (say "Xin" and "Pierre"), you could use the Conditional Rules module to improve that Rules Action to 'Set a data value', so that the value to be used for the term id depends on the value of the node author.

4. Open question

Your question doesn't say "What should happen if no term exists yet for a specific node author?". If such scenario is impossible in your site, then you're lucky (and good to go). Otherwise you'll have to further improve the Rules logic you're implementing to:


get the appropriate (new) term created on the fly.
go find out what the term id is for the newly created term.
improve the Rules Action to 'Set a data value' to actually use the term id of this newly created term.


If you wonder how to do that (also), use this link ... 3 times (one for every bullet).