Copied to clipboard

Flag this post as spam?

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


  • Pinal Bhatt 298 posts 389 karma points
    Mar 16, 2011 @ 14:20
    Pinal Bhatt
    0

    What is the datatype Dropdown list:Publishing Keys?

    What is the datatype Dropdown list:Publishing Keys? How its different from normal Dropdown list datatype.

  • Lee Kelleher 3945 posts 15163 karma points MVP 10x admin c-trib
    Mar 16, 2011 @ 15:07
    Lee Kelleher
    4

    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.

  • Pinal Bhatt 298 posts 389 karma points
    Mar 17, 2011 @ 11:03
    Pinal Bhatt
    0

    Thanks Lee.

  • Heather Floyd 531 posts 787 karma points MVP 2x c-trib
    Apr 23, 2012 @ 17:20
    Heather Floyd
    0

    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

  • Lee Kelleher 3945 posts 15163 karma points MVP 10x admin c-trib
    Apr 23, 2012 @ 17:48
    Lee Kelleher
    2

    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...

    // 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.

    Good luck!

    Cheers, Lee.

  • Heather Floyd 531 posts 787 karma points MVP 2x c-trib
    Apr 24, 2012 @ 23:40
    Heather Floyd
    0

    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

  • 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.

Please Sign in or register to post replies