Copied to clipboard

Flag this post as spam?

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


  • Barbacan 29 posts 79 karma points
    Oct 27, 2014 @ 21:29
    Barbacan
    0

    GetPreValues and single node problem

    Hi, I wrote a tiny function thath should return me the id of a prevalue from a string input. This is the code:

        protected String GetSectionByName(string name)
        {
            String retValue = string.Empty;
            if (!String.IsNullOrEmpty(name))
            {
                XPathNodeIterator iterator = umbraco.library.GetPreValues(1617);
                iterator.MoveNext(); //move to first
                XPathNodeIterator preValues = iterator.Current.SelectChildren("preValue", "");
                System.Xml.XPath.XPathNavigator navProductID = preValues.Current.SelectSingleNode(name);
                if(navProductID != null)
                    retValue = navProductID.GetAttribute("id","");
                else
                    retValue = "NULL";
            }
            return retValue;
        }

    Basically the function still returns empty as the navProductId is always null. I cannot get a single node id by value. Any hints?

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Oct 28, 2014 @ 18:01
    Jeavon Leopold
    100

    Could you use the DataTypeService GetPreValuesByDataTypeId method instead of rolling your own?

  • Barbacan 29 posts 79 karma points
    Oct 29, 2014 @ 16:24
    Barbacan
    0

    This is nice but I would need the opposite. From a string I need to get the numeric preValue. I couldn't find the oppisite methods of GetPreValuesByDataTypeId

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Oct 29, 2014 @ 17:03
    Jeavon Leopold
    0

    What does your string contain exactly?

  • Barbacan 29 posts 79 karma points
    Oct 31, 2014 @ 22:35
    Barbacan
    0

    I have a dropdownlist with publishing keys, so basically a list like:

    scifi  100
    horror  101
    nature  102
    fantasy  103

    I pass the name as a querystring parameter (transformed as a rewrited url), so if my querystring parameter is "fantasy", for example, and I need to extract the preValue 103. Actually I do a foreach but I hope there may be a suitable method. thanks!

     

     

  • 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