The "Dropdown list" data-type should save the text from the dropdown item, where as "Dropdown list, publishing keys" would save prevalue ID.
Unfortunately I don't think there is a quick and easy way to convert the IDs over to text - well not directly in the back-office.
Depending on how comfortable you are with running code against your content/data, you could try the following idea...
// using uQuery, get the published nodes via XPath
var nodes = uComponents.Core.uQuery.GetNodesByXPath("descendant::*[@isDoc and normalize-space(propertyAlias)]");
// loop through each node
foreach (var node in nodes)
{
// get the published value of the dropdown (e.g. the prevalue id)
var prevalueId = node.GetPropertyAsInt("propertyAlias");
if (prevalueId > 0)
{
// get the text value of the prevalue
var dropdownText = umbraco.library.GetPreValueAsString(prevalueId);
if (!string.IsNullOrEmpty(dropdownText))
{
// using uQuery extension, we can set the new value
node.SetProperty("propertyAlias", dropdownText);
// republish the node
node.Publish(true);
}
}
}
Key parts to this code snippet...
* Firstly, make a database back-up. As much as I am trying to help, I don't want you to lose any data! :-)
* The data must be published (e.g. available in the XML cache - umbraco.config)
* Before running the code, swap over the data-type from being a "Dropdown list, publishing keys" to a regular "Dropdown list". Also make sure that the "Database datatype" is set to either Ntext or Nvarchar (depending on which one you want). Now do not save or republish anything.
* For the code snippet, I am using uComponents/uQuery ... it has some good helper methods which will be very useful here. (Make sure to import the "uComponents.Core.uQueryExtensions" namespace into your code too)
* Add the code snippet to a dashboard control, or anywhere else (e.g. could even add it to a masterpage template) - you should only be running this once anyway.
* Replace the "propertyAlias" text with the correct alias, then run the code.
Fingers crossed, this will take the published values from your dropdown (numeric IDs) and swap them out with the text values.
I was able to use a modification of your code to batch update my nodes (and convert to a textstring datatype). It was really helpful and I appreciate it.
What is the datatype Dropdown list:Publishing Keys?
What is the datatype Dropdown list:Publishing Keys? How its different from normal Dropdown list datatype.
Hi Pinal,
The default "Dropdown list" data-type will save the value you select - which would usually be the display text.
Whereas the "Dropdown list with publishing keys" saves the PreValue id (from the database) instead of the text.
You could use "umbraco.library.GetPreValueAsString(int Id)" to retrieve the text value later on.
Cheers, Lee.
Thanks Lee.
I have a "drop-down list" datatype, but it seems to be storing integer IDs (which is causing a problem with my courier transfer).
Any ideas why this is? (If I change the "render control" to "textbox" and look at the Content Node, the value displayed is a number).
Is there any way I can "convert" these values to a text version without having to reset each node individually?
Thanks
Hi Heather,
The "Dropdown list" data-type should save the text from the dropdown item, where as "Dropdown list, publishing keys" would save prevalue ID.
Unfortunately I don't think there is a quick and easy way to convert the IDs over to text - well not directly in the back-office.
Depending on how comfortable you are with running code against your content/data, you could try the following idea...
Key parts to this code snippet...
* Firstly, make a database back-up. As much as I am trying to help, I don't want you to lose any data! :-)
* The data must be published (e.g. available in the XML cache - umbraco.config)
* Before running the code, swap over the data-type from being a "Dropdown list, publishing keys" to a regular "Dropdown list". Also make sure that the "Database datatype" is set to either Ntext or Nvarchar (depending on which one you want). Now do not save or republish anything.
* For the code snippet, I am using uComponents/uQuery ... it has some good helper methods which will be very useful here. (Make sure to import the "uComponents.Core.uQueryExtensions" namespace into your code too)
* Add the code snippet to a dashboard control, or anywhere else (e.g. could even add it to a masterpage template) - you should only be running this once anyway.
* Replace the "propertyAlias" text with the correct alias, then run the code.
Fingers crossed, this will take the published values from your dropdown (numeric IDs) and swap them out with the text values.
Good luck!
Cheers, Lee.
Thanks so much, Lee,
I was able to use a modification of your code to batch update my nodes (and convert to a textstring datatype). It was really helpful and I appreciate it.
~Heather
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.