EMJ
EMJ

Reputation: 11

Merge multivalue field then remove duplicated nodes

I'm open to suggestions as how to fix the following:

How can I iterate through all the nodes, find the nodes with the same key, consolidate the values of the multivalue field, then delete the duplicates?

what about creating a temp content, same fields, to save the newly consolidated node? what is the easiest way to solve this problem?

Multivalue field (checkboxes)
A
B
C
etc

Content:

Key, NID, Title, Other fields, Multivalue field
key1, 1, title1, others1, A
key1, 2, title1, others1, B
key2, 3, title2, others2, A
key1, 4, title1, others1, C

expected results, consolidate the multivalue text field to have a single node: NID can be generated during the temp node creation.

NID, Title, Other fields, Multivalue field (checkboxes checked)
x, title1, others1, "A, B, C"
x, title2, others2, A

Upvotes: 0

Views: 594

Answers (1)

EMJ
EMJ

Reputation: 11

I finally figured out how to remove duplicates, while importing data with feeds, and using rules to consolidate the multi-value field. The following video was very useful to get to the final solution:

https://vimeo.com/28659739

Solution (based on custom needs):

  1. create a key for each record in the csv file (I had many duplicates and no keys, data was not consolidated).
  2. create a temporary field (radio buttons, one value), the field was a Term reference field.
  3. import csv file, utf8 encoded, using the key as unique value (field_validation module).

Settings for Node processor

  • Insert new nodes
  • Update existing nodes
  • Skip non-existent nodes

Importer updated the nodes with the same key, eliminating duplicates and consolidating records with the same information.

A Rule was executed, after updating a node, to add values to the multi-value field.

**Events**
After updating existing content of type Course
Before saving content of type Course

**Conditions**
Data comparison
Selected data: node:field-temp
value: equals
the value to compare

**Actions** 
Fetch entity by id
Value: taxonomy term
value: term id of the term you want to add to the multivalue field
Variable label: term name here
Variable name: custom_var_name

Add an item to a list
Selected list: node:field-multivaluefield
Data selector: custom_var_name
Enforce uniqueness: True.

Save entity
node:field-multivaluefield:0

Upvotes: 1

Related Questions