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.
- 
                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}");
 }
 }
 
- 
                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
                
   
   
 
 
- 
                If you want to add the created entity to a specific unmanaged solution, you can set the solution name accordingly in the SolutionUniqueName property
                
   
 
        Hope This Helps!
    
 
 
Comments
Post a Comment