Copied to clipboard

Flag this post as spam?

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


  • Brendan Rice 538 posts 1100 karma points
    Apr 07, 2022 @ 00:07
    Brendan Rice
    0

    How do you add member property value to a member in v9

    Need to add custom properties to a member and populate them via code.

    How can you do this in v9?

  • Ambert van Unen 175 posts 817 karma points c-trib
    Apr 07, 2022 @ 08:12
    Ambert van Unen
    101

    Well the properties are set in the backoffice (just like documenttypes), but in code you can do this.

    You first need to get the alias of the field, if you're using modelsbuilder you can do it like this:

    var customMemberProperty = Member.GetModelPropertyType(_publishedSnapshotAccessor, x => x.CustomMemberProperty).Alias;
    

    or just use the string alias of the field, in this case "customMemberProperty".

    Then get the member by various means (email or id for example)

    var memberToUpdate = _memberService.GetByEmail(emailAddress);
    

    Then update the values:

    memberToUpdate.SetValue(customMemberProperty, "NewValue");
    

    And save them

    _memberService.Save(memberToUpdate);
    

    Done!

Please Sign in or register to post replies

Write your reply to:

Draft