Copied to clipboard

Flag this post as spam?

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


  • Paul de Quant 403 posts 1520 karma points
    Nov 16, 2017 @ 07:49
    Paul de Quant
    0

    How to save a value to a MNTP programmatically

    Hello,

    Could someone tell me how I should save a value to a Multi Node Tree Picker. I've tried saving a page Id however this is not reflected in the backoffice. Does it need to be saved in a particular format.

    Examples welcome.

    Many thanks

    Paul

  • Ben Palmer 176 posts 842 karma points c-trib
    Nov 16, 2017 @ 08:04
    Ben Palmer
    0

    Hi Paul,

    I haven't done this but at a guess, maybe you need to pass in an IPublishedContent?

    Otherwise, it'd be good to see your code so far and we can go from there.

  • Paul de Quant 403 posts 1520 karma points
    Nov 16, 2017 @ 08:07
    Paul de Quant
    0

    Hi Ben,

    Thanks for the reply, would that be a List

    Thanks

    Paul

  • Matt Darby 28 posts 391 karma points c-trib
    Nov 16, 2017 @ 08:07
  • Paul de Quant 403 posts 1520 karma points
    Nov 16, 2017 @ 13:22
    Paul de Quant
    0

    Hi Matt,

    Thanks for the link, I've tried to no avail to use that code.

    I have managed to get it working, see code below:-

                        if (memberExists)
                    {
                        IMember currentUser = ms.GetByUsername(userName);
    
                        if (currentUser != null)
                        {
                            var findPage = cs.GetById(pageId);
    
                            var loadUdi = Udi.Create(Constants.UdiEntityType.Document, findPage.Key);
    
                            List<string> splitPages = new List<string>();
    
                            if (currentUser.GetValue("favouritePages") != null)
                            {
                                splitPages = currentUser.GetValue("favouritePages").ToString().Split(',').ToList();
    
                                bool checkIfExists = splitPages.Any(page => page == loadUdi.ToString());
    
                                if (!checkIfExists)
                                {
                                    splitPages.Add(loadUdi.ToString());
    
                                    currentUser.SetValue("favouritePages", string.Join(",", splitPages));
                                }
    
                            }
                            else
                            {
                                splitPages.Add(loadUdi.ToString());
    
                                currentUser.SetValue("favouritePages", string.Join(",", splitPages));
                            }
    
                            ms.Save(currentUser);
    
                        }
    
                    }
    
Please Sign in or register to post replies

Write your reply to:

Draft