Updating a property using the api content service in Umbraco 6.x

I created a user control for my Umbraco site that allows administrators to quickly update specific fields on sites without having to navigate the content tree.

So far, my code is working as expected: I can update simple true / false properties without problems. However, now I am trying to update a property that has a user data type, and I am encountering difficulties.

The data type itself is a simple drop-down list that lists a series of availability statuses, i.e. Available, unavailable, sold and reserved. The data type stores text values.

Here is the code I have that allows me to update my true / false properties:

public void ChangeInteractiveStatus(string nodeId, bool chkValue) { var cs = ApplicationContext.Current.Services.ContentService; var apartment = cs.GetById(Convert.ToInt32(nodeId)); apartment.SetValue("displayOnInteractive", chkValue); cs.SaveAndPublish(apartment); } 

This works perfectly fine since the data type of this property is a regular type of true / false data.

Here is the code I use to change the value of my custom dropdownlist data type:

 public void ChangeAvailabilityStatus(string nodeId, string status) { var cs = ApplicationContext.Current.Services.ContentService; var apartment = cs.GetById(Convert.ToInt32(nodeId)); apartment.SetValue("status", status); cs.SaveAndPublish(apartment); } 

As you can see, there are very few differences, but this code does not work.

To check what happens when I update the properties using the above code, I checked the umbraco.config file only to find that the specified property is displayed as follows:

 <status><![CDATA[]]></status> 

However, when I change the value in the content tree (without using my admin control), the value is saved as:

 <status><![CDATA[Sold]]></status> 

So for some reason, when I try to update a value that it rejects, and I cannot understand why.

FYI I tried to enter a value like:

 "<![CDATA[" + status + "]]>" 

But that didn't matter.

Does anyone know how I can fix this? How can I correctly update a property?

thanks

+4
source share
1 answer

Well, I realized what the problem is. It seems that the values were saved as name-value pairs, so the actual value obtained in the database was an integer. As soon as I updated the code to insert an integer identifier, everything worked as expected! Hooray.

+2
source

All Articles