Copied to clipboard

Flag this post as spam?

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


  • roli81 7 posts 58 karma points
    Nov 24, 2023 @ 07:24
    roli81
    0

    Set raw value for a Mulltinode Treepicker Field on an ElementType

    Hi

    I use Umbraco 12.3.3 and I have a blocklist field on my document type. On the element type (used for the blocks) I have a Multinode Treepicker field. Now I would create some blocks programmatically. But no Value would be saved in the Multinode Treepicker field. All oder fields the value would be saved correctly:

        private BlockList.BlockList GetInstrumentLocationBlockList(IEnumerable<InstrumentLocationDto> instrumentLocations)
    {
        BlockList.BlockList blocklistNew = new BlockList.BlockList();
        var instrumentLocationList = new List<Dictionary<string, string>>();
        var contentTypes = _contentTypeService.GetAll();
        var instrumentLocationType = contentTypes.FirstOrDefault(n => n.Alias == Constants.ElementTypes.InstrumentLocation.Alias);
        var dictionaryUdi = new List<Dictionary<string, string>>();
    
    
        foreach (var instrumentLocation in instrumentLocations)
        {
            var contentUdi = new GuidUdi("element", Guid.NewGuid());
    
            if (ContextAccessor.TryGetUmbracoContext(out var ctx))
            {
                List<IPublishedContent> instruments = new List<IPublishedContent>();
    
                foreach (var instrumentId in instrumentLocation.Instruments)
                {
                    var instrumentNode = ctx.Content.GetById(instrumentId);
    
                    if (instrumentNode != null) instruments.Add(instrumentNode);
                }
    
    
    
                instrumentLocationList.Add(new Dictionary<string, string>
                {
                    { "contentTypeKey", instrumentLocationType.Key.ToString() },
                    { "udi", contentUdi.ToString() },
                    { Constants.ElementTypes.InstrumentLocation.Fields.Instruments, string.Join(",", instruments.Select(i => new GuidUdi("element", i.Key)))  },
                    { Constants.ElementTypes.InstrumentLocation.Fields.Lat, instrumentLocation.Lat.ToString() },
                    { Constants.ElementTypes.InstrumentLocation.Fields.Lon, instrumentLocation.Lon.ToString() },
                    { Constants.ElementTypes.InstrumentLocation.Fields.School, instrumentLocation.School },
                    { Constants.ElementTypes.InstrumentLocation.Fields.StreetNr, instrumentLocation.StreetNr },
                    { Constants.ElementTypes.InstrumentLocation.Fields.ZipCode, instrumentLocation.ZipCode },
                    { Constants.ElementTypes.InstrumentLocation.Fields.City, instrumentLocation.City },
                });
    
    
                dictionaryUdi.Add(new Dictionary<string, string> { { "contentUdi", contentUdi.ToString() } });
            }
        }
    
        blocklistNew.Layout = new BlockListUdi(dictionaryUdi);
        blocklistNew.ContentData = instrumentLocationList;
        blocklistNew.SettingsData = new List<Dictionary<string, string>>();
    
    
        return blocklistNew;
    }
    

    I think the problem is on this line:

    { Constants.ElementTypes.InstrumentLocation.Fields.Instruments, string.Join(",", instruments.Select(i => new GuidUdi("element", i.Key)))  },
    

    How do I save the raw value correctly?

    Thx for helping

    Roland

Please Sign in or register to post replies

Write your reply to:

Draft