Copied to clipboard

Flag this post as spam?

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


  • Mark Slade 49 posts 110 karma points
    Oct 25, 2021 @ 11:12
    Mark Slade
    0

    Programmatically adding custom property to member type

    Hi All,

    I am using Umbraco version 8.17.0

    I am trying to add a custom property to a member type using the following code:

    IMemberType memberType = _memberTypeService.Get("Member");
    IDataType textType = _dataTypeService.GetAll().Where(x => x.Name == "Textstring").FirstOrDefault();
    
    PropertyType propType = new PropertyType(textType, "myTestProperty");
    propType.Name = "My Test Property";
    
    memberType.AddPropertyType(propType);
    _memberTypeService.Save(memberType);
    

    All works well and the property gets added to the 'Generic properties' group.

    But, If I then delete it from the back office, then click 'Save' I get the error:

    Validation: The Alias field is required.

    Any ideas what I'm doing wrong?

    Thanks in advance.

    Mark

    Update: If I delete it programmatically, it is removed from the backoffice!

    memberType.RemovePropertyType("myTestProperty");
    _memberTypeService.Save(memberType);
    
  • 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