Copied to clipboard

Flag this post as spam?

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


  • Michaël Vanbrabandt 863 posts 3348 karma points c-trib
    Mar 15, 2016 @ 12:59
    Michaël Vanbrabandt
    0

    Add new member and set custom made member properties

    Hi,

    I have found a piece of code to programmatically create new members. This seems ok but how do I set my custom properties of the member?

    Code to add a new member:

    IMember member = ApplicationContext.Services.MemberService.CreateMember("autodest", "[email protected]", "p00005 - Autoparts Destelbergen ( FILIAAL )", "member");
    member.IsApproved = true;
    
    try
    {
    
         ApplicationContext.Services.MemberService.Save(member);
         ApplicationContext.Services.MemberService.SavePassword(member, "prosec");
         ApplicationContext.Services.MemberService.AssignRole(member.Id, "Prosec Online");
    
    }
    catch { }
    

    For example I have the following custom properties:

    • Branch: Content Picker
    • SalesPerson: Content Picker
    • Code: Textstring
    • Title: Textstring

    /Michael

  • Michaël Vanbrabandt 863 posts 3348 karma points c-trib
    Mar 15, 2016 @ 13:23
    Michaël Vanbrabandt
    100

    Ok, I have found the solution.

    For anyone that was looking for this, below is the solution:

    if (member.HasProperty("branch"))
        member.SetValue("branch", 1079);
    

    /Michael

  • Dennis Adolfi 1082 posts 6450 karma points MVP 6x c-trib
    Mar 15, 2016 @ 13:24
    Dennis Adolfi
    0
    var memberService = ApplicationContext.Current.Services.MemberService;
    var member = memberService.GetById(member.Id);
    member.SetValue("customPropertyAlias", "customValue");
    memberService.Save(member);
    
  • 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