2

We have an item which is having a multilist field in it. This field has selected value and the below code is working fine on English version. Other language versions are returning empty result. We have verified the item and dependent list items have the version of other languages. Please help us to fix this issue.

Code

public static List<Item> GetMultiListItems(Item dataItem, string fieldName)
{
    if (dataItem != null && !string.IsNullOrEmpty(fieldName))
    {
        MultilistField field = dataItem.Fields[fieldName];
        if (null == field)
            return null;

        return field.GetItems().ToList();
    }
    return null;
}
4
  • 2
    Is the dataItem language equal to Sitecore.Context.Language? If not, try to use using new LanguageSwitcher(item.Language) around field.GetItems()
    – Marek Musielak
    Feb 6, 2018 at 9:07
  • Also it is worth to check if you have these items published in the web database for both languages. Check if is there any workflow blocking your publishing for the version of these languages.
    – João Neto
    Feb 6, 2018 at 10:55
  • Thank you guys, we have fixed it by applying LanguageSwitcher where we get the dataItem object.
    – Annadurai
    Feb 7, 2018 at 12:54
  • Comment converted into an answer.
    – Marek Musielak
    Feb 7, 2018 at 13:27

1 Answer 1

1

It looks like your dataItem language is not equal to Sitecore.Context.Language.

Try to use

using new LanguageSwitcher(item.Language)

around the place where you get your dataItem or where you use field.GetItems()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.