Score:0

Set a Data Value from Text field to Term Reference field

us flag

Node has two fields:

  1. Text field
  2. Term reference field (autocomplete?)

The Text field is old and already has 500 nodes with 500 unique values.

The Term reference field is new and needs to contain same data.

So e.g. one node has Text field value of 123, the Term reference field also needs somehow to have it set to 123?

enter image description here

In Rules Set a value data only lets you copy content from term reference field into text field, but not vice versa.

Or on page save it does save a new term based on text field to the taxonomy vocabulary, but the term itself does not show up/gets saved in the node/its term field?

Rule in the making:

enter image description here

Under Actions we select Set a data value and in first screen we select our Taxonomy term reference field that needs to be modified:

enter image description here

And then on a next screen we are stuck, because we cannot select the source for data selector which is a Text field but all available options are only other Term reference fields.

The missing field is added under Conditions with Entity has field (the node:field-enter-product-name-)

No Sssweat avatar
ua flag
If the whole point is to delete the text field and start using an entity reference field, then I would just export those two tables only as CSV file, and copy over the text field and values to the entity reference table and the node id, like I [mention here](https://drupal.stackexchange.com/a/189473/27710).
No Sssweat avatar
ua flag
Alternatively, you could use [views_data_export](https://www.drupal.org/project/views_data_export) module and export as text field as CSV and then import into the entity reference field using the [feeds](https://www.youtube.com/watch?v=yxCzrkcpEvs&ab_channel=LevelUpTuts) module
user3108268 avatar
us flag
@NoSssweat the text field will not be deleted, it will be used for data entry as it was, it's just that data will be copied to the term reference field too (on save?). How do Feeds import CSV with correct terms into correct nodes exactly?
Score:2
mx flag

This works for D7

Term reference field (autocomplete?)

in rules, widget does not affect, you just set values, but leave it as autocomplete, a select list cosumes more resourses

The Text field is old and already has 500 nodes with 500 unique values.

Unique values, this means one unique taxonomy term for each node.

The Term reference field is new and needs to contain same data.

Your taxonomy term title value it will hold the field value

Your events on node: new/update are ok

On your conditions i can't tell mutch, img is not complete, i sugest to include 'field data value IS empty' on your node taxonomy term rerefence field. This will avoid to create duplicate terms and updating same node twice.

Steps:

1.- In actions secction add an accion

2.- create a new entity (term must exist to be assigned as TR to a node by rules)

3.- select from dropdown: taxonomy term

4.- for term name select node title, avilable in data selector mode

5.- select your taxonomy vocavulary

6.- change (optional) variable name and hit save

7.- add another accion: save entity, the new term

8.- add aonther accion: set a data value

9.- now select your updated node and drill down to find term reference field

10.- and set node field value with the term reference you just created

11.- save node, done

EDIT:

Steps to buit a component:

this way you can call it from node/new event or from a VBO to update all old nodes

a.- add a component of type RULE

b.- in parameters seccion add parameter type: node, label: product node, machine name:product_node, save settings

c.- on conditions add: entity has field (your product node): select your term reference field

d.- add another condition: your term reference field is empty

do all accions steps explainded above in rule, now you can call your component any where.

user3108268 avatar
us flag
Hi @pinueve , this saves new taxonomy term to the vocab, but it doesn't save the term into the node.
pinueve avatar
mx flag
I edited my answer, i just added numbres, nothing else, and YES, it does save term into the node (accions 8, 9, 10, 11)
user3108268 avatar
us flag
I have recorded my setup and demonstration can you please review https://streamable.com/v138c1
pinueve avatar
mx flag
nice recording, i did not new that app, thanks, you are missing step 7, is needed, i mensioned on step 2, now you will have 2 save actions, one for term, one for node, and please DO select in these 2 actions: force save entity to true, http://i.imgur.com/PKriyCA.png
pinueve avatar
mx flag
and i recomend you to do it by a component, this way you can call your component from your rule, or by VBO to update all existing nodes, and please follow order in actions explained
user3108268 avatar
us flag
Looks like it's working so far. One more question, how to do same but with Entity Reference field? `Set data value` won't let use `entity_created` for `Data selector`. https://i.imgur.com/lbiJakq.png it adds `:` with more options.
pinueve avatar
mx flag
Let us [continue this discussion in chat](https://chat.stackexchange.com/rooms/128308/discussion-between-pinueve-and-user3108268).
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.