Copied to clipboard

Flag this post as spam?

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


  • Simon 48 posts 108 karma points
    Sep 12, 2017 @ 20:24
    Simon
    0

    content service setvalue multinode treepicker2

    Previous to our upgrade to 7.6.5, we could do the following with the old multinode treepicker using the content service:

    if (ApplicationContext.IsReady) {
        var contentService = ApplicationContext.Current.Services.ContentService;
        var pageResults = contentService.GetChildren(1220);
    
        if (pageResults != null && pageResults.Any()) {
            foreach (var pageItem in pageResults) {
                string pageName = pageItem.Name.ToLower().Trim();
                if (pageName.StartsWith("thing")) {
                    pageItem.SetValue("Brand", 2495);
                } else {
                    pageItem.SetValue("Brand", "2276,2495");
                }
    
                contentService.SaveAndPublishWithStatus(pageItem);
            }
        }
    }
    

    With the new version, we have to use a udi... and I don't know how to set multiple nodes on this property. Example:

    if (ApplicationContext.IsReady) {
        var contentService = ApplicationContext.Current.Services.ContentService;
    
        var thing1 = contentService.GetById(2495).GetUdi();
        var thing2 = contentService.GetById(2276).GetUdi();
    
        var pageResults = contentService.GetChildren(1220);
    
        if (pageResults != null && pageResults.Any()) {
            foreach (var pageItem in pageResults) {
                string pageName = pageItem.Name.ToLower().Trim();
                if (pageName.StartsWith("thing")) {
                    pageItem.SetValue("Brand", thing1.ToString());
                } else {
                    // how to get thing1 and thing2 together???
                    pageItem.SetValue("Brand", thing2.ToString());
                }
    
                contentService.SaveAndPublishWithStatus(pageItem);
            }
        }
    }
    

    Why the change and why doesn't the previous version of this code work anymore?

  • Kevin Jump 2348 posts 14896 karma points MVP 8x c-trib
    Sep 13, 2017 @ 07:23
    Kevin Jump
    0

    Hi Simon,

    The change is to make moving umbraco installs easier (the old Id values change between installations - so if you moved your settings/content from say dev to live then all the links would be broken).

    if your just upgrading you don't have to use the version 2 pickers - there is a setting in umbracoSettings.config that will enable the old property editors (showDeprecatedPropertyEditors), - so you can carry on with the old way.

    The new way . the values are stored in a similar format, to set multiple values you need to comma separate them

    string.Format("{0},{1}", thing1.ToString(), thing2.ToString()); 
    

    should do it (i am sure there are nicer ways)

  • 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