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?
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!
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)
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
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;
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
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
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!
What version of Umbraco are you using ? I am 7.1.4
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)
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
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.
is working on a reply...