How to add an item programmatically to a Contentme...
# help-with-umbraco
c
V13.5.3 Some properties have been added to the Member MemberType. One is a Contentment Content Block which allows blocks to be added to the list of MyData. Each block has a Name, Code, and BrandList:-
Copy code
member
    MyData (block list) {
        Name (textString)
        Code (testString)
        BrandList (Multinode Tree Picker)
        }
An import script has been written to take details from a csv file to create new members. This works fine, but the MyData blocks can't be updated . ChatGPT reports that IPublishedElements are "immutable" and so can't be changed directly. Here's the line that gets MyData as an IEnumerable.
var myList = theNewMember.GetValue<IEnumerable<IPublishedElement>>("myData") ?? Enumerable.Empty<IPublishedElement>();
I need to be able to add new IPublishedElements to myList. Any ideas would be appreciated. Thanks.
b
@Craig100 if you doing any operations on list, you should use list / array not IEnum, anyway that sounds weird you can modify Mydata 🤔 and not sure what exactly you trying achieve here, are you updating user? if so you should probably work on Source values not TargetValue (post converter values)
c
What I'm trying to acheive is to create a new Member and add data to it. The data is supposed to be held in Contentment Content Block Lists. Nested Content would have done but it's been discontinued. So when you say work on Source values rather than Target values, do you mean work on IContent rather than IPublishedElement? If so, not sure how to get hold of the content for the Block List.
b
@Craig100 what I meant working on Json behind IPE, you can work with IPE but that make things harder in this case
c
I have no idea how to get to the Json behind the IPE
b
theNewMember.GetProperty(alias).SourceValue if I am not wrong :), but if yo want work on IPE if you share with me code with context I can have a look tomorrow how to get it work on IPE as for me it is missing some bits and cant connect dots
c
ChatGPT is having a go, but I don't hold out much hope, lol
b
you might also want to check usync people edition code as usync also modifies information inside of properties
9 Views