Copied to clipboard

Flag this post as spam?

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


  • Chris Lord 15 posts 51 karma points
    Jun 17, 2014 @ 13:26
    Chris Lord
    0

    Content Service - Dropdown Datatype

    Hi All,

    I have created a data type called "Gearbox Type" which is using the drop down list editor, and has the following values;

    • Manual
    • Automatic
    I have added a property to my "Gearbox" Doc Type which uses this Data Type. I am migrating data from an old system, and I need to populate this when creating the content using the content service. My code is;

    var cs = Services.ContentService;
    var c = cs.CreateContent("Chris Test", 1267, "Gearbox");
    c.SetValue("historicId", "12345"); - this is a text string
    c.SetValue("gearbox", "Manual"); - this is my dropdown
    c.SetValue("forwardGears", "10"); - this is a text string
    cs.Publish(c);

    When the content is created, the text string properties are saved OK, but my dropdown value is not selected. If I inspect the element I can see the Id's of each option and if I try the following, it doesn't work either;

    c.SetValue("gearbox", 1) or c.SetValue("gearbox", "1");

    What am I doing wrong here, has anyone done this before and can help out?

    Cheers

    Chris

  • awm 187 posts 376 karma points
    Jun 17, 2014 @ 14:40
    awm
    0

    Well in case it's of any help I figured out a solution to my problem. You can see it here: http://stackoverflow.com/questions/18900069/updating-a-property-using-the-content-service-api-in-umbraco-6-x

  • Chris Lord 15 posts 51 karma points
    Jun 17, 2014 @ 17:05
    Chris Lord
    0

    Thanks I saw your post, I can't seem to get this working whether I use the ID or the Description. When you say ID, I assume you mean the value, which Umbraco creates, I can't specifiy the ID in the UI, I can just add the description?

    If I try and access the property @Umbraco.Content(1316).GearBox, the value is returned, so it's storing in the database, but I need to have it selected for the content administrator!

     

  • Chris Lord 15 posts 51 karma points
    Jun 17, 2014 @ 17:06
    Chris Lord
    0

    What version of Umbraco are you using ? I am 7.1.4

  • awm 187 posts 376 karma points
    Jun 17, 2014 @ 17:39
    awm
    0

    I was using version 6.x although I wouldn't have thought it'd made much difference since AFAIK the process isn't any different in 7? (someone please correct me if I'm wrong)

  • Chris Lord 15 posts 51 karma points
    Jun 17, 2014 @ 17:47
    Chris Lord
    0

    Yeah , I think I have found the issue, I need to get the ID of the prevalue from the cmsdatatypeprevalues table, and use that ID when using the setvalue, I think there is a way to get that based on the text, so will look into it, thanks for your time in responding to my post

  • awm 187 posts 376 karma points
    Jun 17, 2014 @ 17:51
    awm
    0

    No worries - I was on the verge of tearing out handfuls of hair trying to figure this one out.. I just hope I can spare someone else the pain, haha.

Please Sign in or register to post replies

Write your reply to:

Draft