Gravatar for sathis.k.durairaj@accenture.com

Question by Sathis, Jun 24, 2015 8:54 AM

Sitecore Reference Field Mapping based on the language

How to map the reference item based on the parent item language?

Here is the scenario: I have one dropdown field which holds the reference to the other sitecore item. Both parent and reference items are in multiple languages. We are using the mapping file to get the reference field item details. We are able to crawl the parent item in multiple langues but reference item details are coming in default language(en) for all the parent language item.How to map reference field based on the parent item language?

1 Reply
Gravatar for jflheureux@coveo.com

Answer by Jean-François L'Heureux, Jun 24, 2015 9:36 AM

If I understand correctly, you are indexing your Sitecore instance with the CES Sitecore connector and are using foreign keys feature to index a parent item field on your child items as described at step 2c of Creating and Using a Sitecore Mapping File. You have multiple languages of the parent item and children items.

If I take the documentation example with artists. The key field value of the foreign key is %[ID] which is the same for all the languages of an item. So multiple documents with the same key value will be indexed.

<Mapping type="885063B0-3451-4B6C-98E3-5AB502C80B36"> <!-- Artists -->
  <Fields>
    <Field name="Artist">%[ID]</Field>
    <Field name="ArtistName">%[Name]</Field>
  </Fields>
</Mapping>

To solve this problem, we could add the item language in the key field value in the mappings of both the artist and the other items that relies on artists like this:

<Mapping type="885063B0-3451-4B6C-98E3-5AB502C80B36"> <!-- Artists -->
  <Fields>
    <Field name="Artist">%[ID]%[Language]</Field>
    <Field name="ArtistName">%[Name]</Field>
  </Fields>
</Mapping>
<Mapping type="Album Template ID"> <!-- Albums -->
  <Fields>
    <Field name="Artist">%[ID]%[Language]</Field>
  </Fields>
</Mapping>

This way, a child item will always get its ArtistName field value from the artist document of the same language. However, if the artist document in that particular language doesn't exist, the ArtistName field will be blank.

Ask a question