Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Andrew 25 posts 148 karma points
    Apr 09, 2019 @ 13:44
    Andrew
    0

    Setting Value for Content Picker

    Hi,

    I'm creating a new page using the content service, and trying to set the value of a content picker of the new page using the code below

    IContent c = contentService.Create(ic.Name, guid, "contentPage", -1);
    c.SetCultureName(ic.Name, "en-US");
    var locaUdi = Udi.Create(Constants.UdiEntityType.Document, ic.Key);
    c.SetValue("content", locaUdi.ToString());
    contentService.SaveAndPublish(c);
    

    However, I keep getting the following error:

    An exception of type 'System.NotSupportedException' occurred in Umbraco.Core.dll but was not handled in user code Additional information: Variation "null,null" is not supported by the property type. occurred

    I've had a look at this answer but still getting the error above.

    I was wondering what the correct way would be to set the content for a content picker? I've tried using the Id and guid as well but neither of these seemed to work either

  • Corné Strijkert 80 posts 456 karma points c-trib
    Apr 09, 2019 @ 19:03
    Corné Strijkert
    100

    Hi Andrew,

    Try setting the culture on the SetValue method like this:

    c.SetValue("content", locaUdi.ToString(), "en-US");
    

    Because the error says: Variation "null,null" is not supported. It seems that the culture/variation is needed.

    It is the same approach you already did with c.SetCultureName(ic.Name, "en-US"); for the content object. The same is needed for each value that is culture specific.

    I haven't tried it myself yet, but I think when you set the Varying by culture property to false on the "content" property, the problem is solved too.

  • Andrew 25 posts 148 karma points
    Apr 10, 2019 @ 08:26
    Andrew
    0

    Ah I see, brilliant thanks Corné, yeah that did the job! Thanks again for your help :)

  • Alaa Abdullah 6 posts 76 karma points
    Aug 19, 2020 @ 14:47
    Alaa Abdullah
    0

    Hi, could you please guide on where i have to add this value as i am new in Umbraco

Please Sign in or register to post replies

Write your reply to:

Draft