You need install http://drupal.org/project/field_collection_feeds. Here is an example how to use it:

1) There is a content type "ebook", it has 3 fields:

field_isbn - ebook's ISBN (this is unique)
body - ebook's description
field_page_content - this is a "field collection"

You will need to create or import content for this content type first, before you can import the field collection data (you cannot import it in the same step).

The content type needs to have a unique field on it (in this example, it is the ISBN).

2) In the "field_page_content" field collection, there are 3 fields:

field_page_number - textfield for page number, 1,2,3,4, ..., 150,151 (this is unique)
field_page_image - an image field
field_page_audio - an file field which store audio info for current page.

In the data you are importing, these three fields need to be associated with the unique content item field from step 1 (in this case, the ISBN). Also, you need to have a unique field in your imported data (in this case, it is field_page_number).

3) Create an importer for "field_page_content" using the "Field collection feeds" module.

To do this, you will need to add an Importer from the Fields Importers page (admin/structure/feeds). There is general documentation on how to do this on: https://drupal.org/node/638804

In the Processor area, choose "Field collection processor".

Here is the configuration for "Processor" > "Field collection processor" > "Settings":

Update existing field collection item : Update existing field collection item
Field name : field_page_content
Host entity type : node
Is field : checked(TRUE), (it is used for mapping target "Host Entity GUID")
Field/property name of Host entity GUID : field_isbn, (this is used for mapping target "Host Entity GUID" -- here you need to type in the machine name of the unique field in your content type that is associated with the data you are importing)
Identifier field name : field_page_number, (this is used for mapping target "Identifier Field" -- here you need to type in the machine name of the field in your field collection that is unique for the individual imported item)

Here is the Mapping for "Processor" > "Field collection processor" > "Mapping":

isbn (csv column) : Host Entity GUID (this will go into the field you entered in "Host entity GUID" on the settings panel)
number (csv column) : Identifier Field (this will go into the field you entered in "Identifier field" on the settings panel)
number (csv column) : Page number (field_page_number)
image (csv column) : Page image (field_page_image)
audio (csv column) : Page audio (field_page_audio)

You must set "Host Entity GUID" and "Identifier Field" mappings.

4) Import your field collection data.

Comments

yurgon’s picture

How to update colloections ?

g089h515r806’s picture

after you set "Identifier field name", you could update your field collection items.

Chinese drupal tutorials Think in Drupal

Ground Unit’s picture

Perhaps i missed something, but it is not very clear to me:
Field/property name of Host entity GUID - Can it be node ID, title...? How can I make it use host node ID?
Identifier field name - What is it: field from CVS file? Some field in field collection? Some field in host node? Can it be field collection ID? How can i make it?

g089h515r806’s picture

1,yes, it could be node id, title, you need set "is field" to FALSE.
2,A field in field collection item that is unique.

Chinese drupal tutorials Think in Drupal

Methos-1’s picture

I also tried to use Node ID for the Host entity GUID but I got the following error message:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'node.nodeid' in 'where clause'
What do I need to use? I also tried "nodeid", "node id", "node.id" without any luck.
If I used the "title" for the Host entity GUID it worked but in my case the Node ID would be better.

Thank you for your help

mobonobomo’s picture

Try 'nid' (without the ') for node id.

hidebuh’s picture

could you teach me how I can associate a field collection with a node by nid, which's already existed since the node has been created when I import a field collection?

I tried to do that by setting like below in D7...
[at processor]
Field/property name of Host entity GUID -> nid
Identifier field name -> unique_no of the field collection

[at mapping]
unique_no of the field collection -> Identifier Field
nid -> Host Entity GUID

but it returns 'Unable to save a field collection item without a valid reference to a host entity' when I try to import the field collection.

could you tell me what it means?
and, what it did I make any mistake for what I intend to do?

PS I'm sorry for my poor English and I'm just a beginner in drupal. If what I wrote above is not understandable to you, plz let me know the point I should make more clearly...

Thank you!

trzcinski.t@gmail.com’s picture

What is the method you use to import the data? Are you sure that it contains the NID column?

The thing is that feeds go through your input data row by row (or element by element) and try to find a NID to match with existing node in your system (host entity). If such node does not exist - or - if you don`t supply it`s nid - importer will return this error.

So in case you use CSV file as input it should have at least those two columns (with data of course): nid and unique_no

whatsupdrew’s picture

What is the best way to create a feed for this field collections parser? I have tried Views Data Export module. That seems to turn images fields and field collections into HTML when you choose XML file type and CSV file type formats the field collections incorrectly. Any thoughts?

sn.ahsanali’s picture

I get this error in feed logs SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '))' at line 1. Any idea what might be the problem ?

Jason Dean’s picture

I'm getting the same error, and failed importing of field collection items.

I followed the instructions above, and am using XPath XML parser. Wonder if that could be the problem?

gswebmaster’s picture

Hi,

I'm running the latest version of Drupal, feeds, field-collection, and field-collection-feeds. However I'm having difficulty getting feeds to import my field collections.
Here's what I'm trying to do. I have three different field collections I will eventually want to import but they all have similar structures so I hope we can just get this first one working.

I have a content type "Departments".
It has a field collection field "Faculty"
"Faculty" contains several fields like any field collection such as..

  • Name
  • Status
  • Degree

Each "Faculty" field-collection is also "unlimited" and so each department will have several "Faculty" fields with different Delta's

I have followed the instructions above in an attempt to import the "Faculty" field to the "Department" nodes I currently have on my website.
Here are the settings I am using with Feeds Importer (I will start with Parser assuming the other settings are irrelevant. assume all settings at default unless otherwise indicated)

  1. CSV Parser (comma delimeted with headers. basically left to default)
  2. Processor: Field Collection Processor
  3. Field Collection Settings:
    • Update existing field collection item : Update existing field collection item
    • Field name : field_dep_faculty (machine name for field collection field)
    • Host entity type : node
    • Is field : checked(TRUE)
    • Field/property name of Host entity GUID : title (using the title of the node? I have also tried assigning a simple integer to each "Department" node with no success)
    • Identifier field name : field_dep_faculty_name (name field within faculty field collection. I'm not sure what to use for these last two. They are unique values but not always integers)

    Here are my mappings:
    hostid Host Entity GUID
    name Name
    namem Identifier Field
    status Status
    degree Degree

Please help me understand what settings I need to change. I've tried all sorts of variations with no luck importing the values. Also I am concerned about how to get the multiple values in with their delta values.

Thanks for the help!
gswebmaster

g089h515r806’s picture

try with following config:
Update existing field collection item : Update existing field collection item
Field name : field_dep_faculty (machine name for field collection field)
Host entity type : node
Is field : checked(FALSE)
Field/property name of Host entity GUID : title (using the title of the node? I have also tried assigning a simple integer to each "Department" node with no success, title is a property.)
Identifier field name : field_dep_faculty_name (name field within faculty field collection. I'm not sure what to use for these last two. They are unique values but not always integers, )

Field/property name of Host entity GUID : a field or property that is unique in Host entity, use it to fetch Host entity.
Is field : whether it is a field or property. I need put this option after "Field/property name of Host entity GUID" instead of above it.
Identifier field name : it is field that unique in your field collection of one host entity

Chinese drupal tutorials Think in Drupal

tkarpagamoorthy’s picture

in the same requirement, I have set the settings. but i cant able upload the file. i can see the file link but cant able to open the local drive.

Please assist me...

stevej1238’s picture

I am having a dificult time making this work also. When I have more than one field collection in my CSV columns it take the last field collection and ignores the first ones.

dotnhack’s picture

I have a problem, not sure if this module can do it, so I'm asking.

I have a book store. field_genre (fiction, nonfiction, trailer etc...) If I make a text field, no problem, I can import using Feeds and my CSV file. But I can't filter by genre in Views, because it is a text field. If I use Integer:list, I can't feeds the data to the database from my CSV because it is not separating the genre for each field like you would with manually value...

I tried manually to add the values in the fields and then load the CSV, but that didn't work either.

It works for Year though (ie. for number)... Can anyone help or point to the right module (I tried Tamper, didn't seem to work).

Thanks,
Mario

g089h515r806’s picture

Try it with feeds tamper module.

Chinese drupal tutorials Think in Drupal

Ne0nka’s picture

do u have an xmlrpc post for create or update field-collection-item?

tritrivi’s picture

I have set up a Feed Importer using Field Collection Feeds but when I run the import it only brings in the first occurrence of the field collection data. This feed is set up as an Xpath XML parser and the Nodes I am updating with this information already exist from a previous feed importer. Below is a simplified version of the XML file I am trying to import. Only the first group gets imported. Is there something I'm missing in my XPath XML Parser settings that will get it to step through and grab each grouping and populate my Field Collection? Thanks.

<DIF>
   <Entry_ID>GES_DISC_AIRH2RET_V005</Entry_ID>

   <Related_URL Type="GET DATA">
      <URL_Content_Type uuid="3c2a68a6-d8c2-4f14-8208-e57a4446ad71">
      <Subtype>ON-LINE ARCHIVE</Subtype>
      </URL_Content_Type>
      <URL>ftp://airsl2.gesdisc.eosdis.nasa.gov/ftp/data/s4pa/Aqua_AIRS_Level2/AIRH2RET.005/</URL>
      <Description>
         Access the AIRS/Aqua Level 2 Standard Products (With HSB) data by FTP.
      </Description>
   </Related_URL>

   <Related_URL Type="GET DATA">
      <URL_Content_Type uuid="9b05d2a3-9a5a-425c-b6ed-59e0e56814fa">
      <Subtype>MIRADOR</Subtype>
      </URL_Content_Type>
      <URL>http://mirador.gsfc.nasa.gov/cgi-bin/mirador/homepageAlt.pl?keyword=AIRH2RET</URL>
      <Description>
         Access the AIRS/Aqua Level 2 Standard Products (With HSB) data using Mirador.
      </Description>
   </Related_URL>

   <Related_URL Type="GET DATA">
      <URL_Content_Type uuid="62919237-f020-4f9d-abcb-3d46b9b021e6">
      <Subtype>OPENDAP DIRECTORY (DODS)</Subtype>
      </URL_Content_Type>
      <URL>http://airsl2.gesdisc.eosdis.nasa.gov/Aqua_AIRS_Level2/AIRH2RET.005/contents.html</URL>
      <Description>
         Access the AIRS/Aqua Level 2 Standard Products (With HSB) data through OPeNDAP.
      </Description>
   </Related_URL>

</DIF>

My XPath expressions for each of the fields are as follows:

//DIF (Context base query)
Related_URL[@Type='GET DATA']/URL_Content_Type/Subtype
Related_URL[@Type='GET DATA']/Description
Related_URL[@Type='GET DATA']/URL
Related_URL[@Type='GET DATA']/URL_Content_Type/@uuid

tritrivi’s picture

I just discovered that I can get all of the Related_URL elements groups to import if I change the "Number of Values" setting for each fields in the Field Collection to "Unlimited". But that is not how I want the information stored in Drupal since the information will lose its relationship to other fields in the grouping. This the whole idea behind having a Field Collection. I do have the Field Collection field in the parent node set to "Unlimited" for "Number of Values" so why won't the Field_Collection_Feeds module import multiple groupings of information into the Filed Collection ? Seems like a bug to me. Any ideas or patches to fix this?

Thanks

tritrivi’s picture

My XPath expressions needed to be set up as follows to handle the repeating group:

//DIF/Related_URL[@Type='GET DATA'] (Context base query)

URL_Content_Type/Subtype
Description
URL
URL_Content_Type/@uuid

Eranga’s picture

Hi,
How we can map Host Entity GUID and Identifier Field when we set Context base query like that?

Eranga’s picture

I finally could fixed it referring XML x path syntax here. Your post helped me. Thanks

darksnow’s picture

How did you solve the issue?

I've been strugling with the same problem and while the XPath debug is showing all the matches, the system is only importing one.

DrupalHack’s picture

Everyone, this thread is old, and we're all facing the same challenge. When you find a solution, please take 5-6 minutes to think through and clearly post your success story.

I'm facing the same challenge, I have a poorly formatted feed that I cannot alter:

<Product>
     <ProductID>1 (unique)
     <productName>Tom Sawyer
     <ProductCategory>Classic
          <OptionCategory>1 (unique)
          <Heading>Editions
          <Options> ------------  (begin field collection loop)
               <OptionID>202 (unique)
               <Cover>Hardcover
               <PriceDifference>40
          </Options>  ------------- (end field collection)
    </ProductCategory>
</Product>

The Host Entity GUID is set to ProductID
The field collection identifier is set to OptionID

From the comments above, I was able to tighten the context and finally get a loop going for the field collection: //Product/ProductCategory/Options

But as another commentor asked/pointed out, when we tighten down the context, the Host Entity GUID is then outside of the defined context. So I'm now able to loop the field collection, but it gives every product every available option, and duplicates them on every cron run.
I've been working on this for about 12 hours. If anyone can help it would be greatly appreciated.

darksnow’s picture

Not really clear on what your problem his here, but I solved my issue by using ../ in the path for the host GUID.

That way you can define the correct base path for the import but have the parent GUID lookup the parent level in the hierachy and associate correctly.

I hope I've understand your issue and that my solution helps.

DrupalHack’s picture

Holy crap... Thank you very very much.

Okay, so to recap:

To import multi value field collections, first build an importer for the parent content that the field collection is attached to, and import.
Then, set up an importer for the field collection as outlined at the top of this page.
To get a loop going on the field collection, tighten the context so that it begins at the root field collection property
ex:

<parent>
   <ParentNode>
   <ParentNodeID>
      <FieldCollection>
         <FieldCollectionID>
         <FieldCollectionTitle>
      </FieldCollection>
   </ParentNode>
</Parent>

The Context would be: //ParentNode/FieldCollection

When setting the Host Entity GUID in the XPath field parser settings, use ../ to back out of the context to the parent property as needed. For the example context above, the XPath would be ../ParentNodeID.

Currently, 10/20/15, you'll need to install the patch in #25 here in order to avoid a field permission error in the field collection feeds module.

I'm going to keep looking for a way to loop a field collection within a field collection, but this is enough to get my project moving again. Thanks again.

GopherWild’s picture

This thread has been a lot of help in getting my feeds set up. Thank you.

One problem I seem to be unable to get around is this error...
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '....user_id = 'smith01')' at line 1

Everything loops correctly and looks as if it will import the correct values for the correct people, but then it throws the error (one error each loop) and imports nothing.

What am I missing?
Thank you for any help you can provide!

Here's my setup...

I have two feeds importers:

  1. People Importer (for Person content type)
  2. People Field Collection Importer (for field collection "field_affiliation" in Person content type)

Person - Content Type
My Person content type has a unique value for each person called: User ID (field_user_id).
Each Person can have several affiliation field collections.

The Field Collection field_affiliations contains the following fields:
Label, Machine Name
Group Name, field_group_name <---- unique - one person belong to each group only once
Group Role, field_group_role <---- not unique - one person may have the same role in this group as in another

People Field Collection Importer Settings:

Basic: User standalone form, Periodic Import OFF, Import on submission

Fetcher: File

Parser: XML Xpath parser
Settings:
Name, Machine Name, Value
Context, ,//people/person/attribute/affiliation
a_affiliation, a_affiliation, a_affiliation
a_role, a_role, a_role
../../user_id, _user_id, ../../user_id

Processor: Field collection processor
Settings:
Field collection field_affiliations
Update existing field collection item
Field name: field_affiliations
Host entity type: Node
Is Field: FALSE
Field/property name of Host entity GUID: ../../user_id
Identifier field name: field_department

Mapping:
Source, Target, Target Configuration
a_affiliation, GUID, Used as unique
a_affiliation, Group Name
a_role, Group Role
../../user_id, Host Entity GUID

XML File (example)

<people>
    <person>
        <user_id>smith01</user_id>
        <attribute>
            <affiliation>
                <a_affiliation>Blue Team</a_affiliation>
                <a_role>Leader</a_type>
            </affiliation>
            <affiliation>
                <a_affiliation>Red Team</a_affiliation>
                <a_role>Member</a_type>
            </affiliation>
            <affiliation>
                <a_affiliation>Green Team</a_affiliation>
                <a_role>Member</a_type>
            </affiliation>
        </attribute>
    </person>
    <person>
        <user_id>gary76</user_id>
        <attribute>
            <affiliation>
                <a_affiliation>Blue Team</a_affiliation>
                <a_role>Rookie</a_type>
            </affiliation>
            <affiliation>
                <a_affiliation>Red Team</a_affiliation>
                <a_role>Member</a_type>
            </affiliation>
            <affiliation>
                <a_affiliation>Green Team</a_affiliation>
                <a_role>Member</a_type>
            </affiliation>
        </attribute>
    </person>
</people>
As If’s picture

Here is the configuration recipe I used to import a field collection into Profile2...

Settings for Field collection processor
Do not update existing field collection item
Field name: (The machine-readable name of the field collection)
Host entity type: Profile
Is field: unchecked (FALSE)
Field/property name of Host entity GUID: pid
Identifier field name: pid

Mapping for Field collection processor
guid => GUID (Used as unique.)
pid => Host Entity GUID
(and my other fields of course)

A few notes:
pid: this is the Profile ID.
guid: this is an arbitrary but unique number, it must be higher than the highest item_id in the field_collection_item table. I used Excel to autofill this whole column with sequential numbers.

Worked great. Excellent module.

-------------------------------------------
Interactive Worlds and Immersive Obsessions
http://www.asifproductions.com

Jacqs’s picture

Here I'm trying to do the same importing users into a drupal recruiter installation.
In that distribution the user has multiple profile2, which one of them the "resume" one contains multiple field collection.

I've followed the recomendations from this thread and from As If comment but the import is not working, in the best case the data is inserted multiple times but its not associated with the correct profile2.
Anyone manage to import this kind of profiles with multiple field collection?
Cheers

amenity’s picture

FWIW, I'm trying to follow this documentation and there are several discrepancies with the Field collection processor > Settings interface:

  • Node is not an option for Host Entity Type.
  • Above, it describes Identifier field name as "used for mapping target "Identifier Field" -- here you need to type in the machine name of the field in your field collection that is unique for the individual imported item)." But on the interface, it says "Machine name of the identifier field which is unique in host entity."
thatpixguy’s picture

Is there some way to use feeds_item.guid as the Host Entity GUID?

I can't seem to work out how to do it, as it's neither a field or a node parameter.

As a work-around I'm using node.title as my Host Entity GUID, but all of my other Feeds Importers use feeds_item.guid for cross references.

lazzyvn’s picture

I test with my application company and contact, In my case one compay have a lots of contact so company is content node and contact is collection field
it works only one line contact imported

Node type = company (title,field_address,field_fc_contact)
field_fc_contact have 2 fields
field_name,field_phone

my file csv
title;field_name;field_phone
com A;Smith;12345
com A;Eve;98756
com B;Susan;6582
com B;Kelly;45987

result 4 imported but i check it again in my com A i have only Smith 12345; and com B only line Susan 6582
how can i fix it?

edvanleeuwen’s picture

I have several profile types which contain field collections. It took me a lot of time to get things working. This is the config that worked for me. For future reference and help for others, I hope.

Profile type: Contact
- Field: Phone (system name 'phone') as embedded Field collection:
-- Field: Type (List), system name 'type'
-- Field: Number (Text), system name 'number'

So basically I want to store a repeating group of phone number, each consisting of a type (e.g. 'Cell' or 'Home') and a unique number.

Import file:
- column 1: User Name
- column 2: Phone Type
- column 3: Phone Number

Feeds Importers, Processor tab (relevant fields)

Settings
- Bundle: Field collection phone
- Field name: phone
- Host entity type: Profile
- Is field unchecked (so a property of Profile is used)
- Field/property name of Host entity GUID: pid
- Identifier field name: pid

Created a view to display user names and profile id's (PID)
Entered the PID in the import file adjacent to the user names

Mapping
- Phone Number - Number
- Phone Type - Type
- PID - Host Entity GUID
- Phone Number - GUID - unique

So when importing, the following is carried out:
- from the import file, the host entity GUID is read
- the PID entry is used to find the profile of the user
- from the import file, the Number and Type are read
- this field is added to the entry created
- the GUID prevents creating double entries

Troubleshooting:
Open the Log tab and verify that the import is read properly (original item) and check that the proper Host Entity is used.

Best regards,

Ed

atiras’s picture

I know this is an old thread, but I'm hoping somebody is still around. I'm failing miserably to import a set of field collections (from HTML if it matters).

Target data structure:

Individual (unlimited number of these)
Individual ID (used to create a unique Path for the Individual record which is also used as the GUID)
Field Name, Email, Phone
Field collection Events (unlimited number of these)
Event 1 Label, Date, Detail, UniqueID (4 fields, including one unique acrsss the target site)
Event 2 Label, Data, Detail, Unique ID
etc...

Each Individual node is created in two Feed importers operating on the
1. to create the Individual nodes each with a unique path/GUID and some non-field collection fields (this works fine)
2. to create multiple Events for each Individual (this is the problem)

Settings for the Events Importer

Parser context: //table[contains(@class,'events')]
Parser UniqueID: tbody/tr/td[1]
Parser field1: tbody/tr/td[2] to Parser field4: tbody/tr/td[4]
Path: .././/*[@class='gs-pe-id']

The parser is working fine.

Processor: Field collection
Bundle: Field collection field_events
Insert new item, update existing item, delete non-existent item
Field name: field_events
Host entity type: Node
Import id, feed nid and Host entity Guid all left blank
(There is no identifier field name in this set of options)

Mappings:
((various mappings for field2 to 4))
path => Host Entity GUID
uniqueid => GUID (used as Unique)

What do I need to do to get this to work? At present, for each node only the first field collection is imported.