CREATE DYNAMICS 365 ENTITY IN SDK

In this post, we will learn how to create a Dynamics 365 custom entity in SDK and how to set some of its properties.

  1. The below function can be used to create a custom entity

    public void CreateEntity()
    {
    CreateEntityRequest createrequest = new CreateEntityRequest
    {
    Entity = new EntityMetadata
    {
    SchemaName = "cak_CustomEntity",
    DisplayName = new Label("Custom Entity", 1033),
    DisplayCollectionName = new Label("Custom Entities", 1033),
    Description = new Label("Custom entity created using SDK", 1033),
    OwnershipType = OwnershipTypes.UserOwned,
    IsActivity = false,
    IsBusinessProcessEnabled = true,
    IsAuditEnabled = new BooleanManagedProperty(true),
    IsSLAEnabled = false,
    },
    PrimaryAttribute = new StringAttributeMetadata
    {
    SchemaName = "cak_name",
    RequiredLevel = new AttributeRequiredLevelManagedProperty(AttributeRequiredLevel.None),
    MaxLength = 100,
    FormatName = StringFormatName.Text,
    DisplayName = new Label("Name", 1033),
    Description = new Label("Primary attribute for the custom entity.", 1033)
    },
    HasActivities = true,
    HasNotes = true,
    SolutionUniqueName = "CAK",
    };
    try
    {
    var result = AdminService.Execute(createrequest);
    if (result.Results != null)
    Console.WriteLine("Custom Entity successfully created!");
    }
    catch (Exception e)
    {
    Console.WriteLine($"Error while creating the custom entity. \n\rError message: {e.Message}");
    }
    }

  2. Based on your needs, you can add or remove the properties you want to set for the entity you want to create or its primary field
    Create entity request 1

    Create entity request 2

  3. If you want to add the created entity to a specific unmanaged solution, you can set the solution name accordingly in the SolutionUniqueName property
    Create entity request 3

Hope This Helps!

Comments

Popular posts from this blog

DYNAMICS 365 HOW TO HIDE RECENT RECORDS FOR LOOKUP FIELD IN UCI

SEARCH BY GUID IN DYNAMICS 365

SAVE FORM IN DYNAMICS 365 JAVASCRIPT