Copied to clipboard

Flag this post as spam?

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


  • Sören Deger 733 posts 2844 karma points c-trib
    Feb 23, 2016 @ 12:05
    Sören Deger
    0

    How can I create RelationType with API?

    Hello,

    how I can create a relationType with API? It seems that the RelationService contains no method for this and I can't find any RelationTypeService?

    Cheers, Sören

  • Comment author was deleted

    Feb 23, 2016 @ 12:13

    Hey Soren,

    Check out the code for the relation type UI, it seems you can use the RelationService https://github.com/umbraco/Umbraco-CMS/blob/dev-v7/src/Umbraco.Web/umbraco.presentation/umbraco/developer/RelationTypes/NewRelationType.aspx.cs

  • Sören Deger 733 posts 2844 karma points c-trib
    Feb 23, 2016 @ 12:28
    Sören Deger
    0

    Hi Tim,

    thank you very much! This works great :-) #h5yr!

    Here is my complete code for creating a bidirectional relation type between two content nodes (document to document):

    var newRelationTypeAlias = "TestRelation";
    
    var relationService = Services.RelationService;
    var relationType = new RelationType(new Guid("C66BA18E-EAF3-4CFF-8A22-41B16D66A972"),
                            new Guid("C66BA18E-EAF3-4CFF-8A22-41B16D66A972"), newRelationTypeAlias, "TestRelationName")
                            {
                                IsBidirectional = true
                            };
    
    relationService.Save(relationType);
    

    Cheers,

    Sören

  • Comment author was deleted

    Feb 23, 2016 @ 12:29

    Great, glad you have it working!

Please Sign in or register to post replies

Write your reply to:

Draft