Create Entity Request
murati opened this issue · comments
When I submitted a create entity request, it throws an exception:
Attribute of type AttributeMetadata cannot be created through the SDK. Based on my research it gives me this error because of lookup fields but unfortunately, the SDK does not allow us to set Attributes since it is readonly.
Any ideas?
Hi @murati,
I used LinqPad for a quick test and it created the entity without problems...
code is from the Microsoft Samples:
var _customEntityName = "new_BankAccount";
CreateEntityRequest createrequest = new CreateEntityRequest
{
//Define the entity
Entity = new EntityMetadata
{
SchemaName = _customEntityName,
DisplayName = new Label("Bank Account", 1033),
DisplayCollectionName = new Label("Bank Accounts", 1033),
Description = new Label("An entity to store information about customer bank accounts", 1033),
OwnershipType = OwnershipTypes.UserOwned,
IsActivity = false,
},
// Define the primary attribute for the entity
PrimaryAttribute = new StringAttributeMetadata
{
SchemaName = "new_accountname",
RequiredLevel = new AttributeRequiredLevelManagedProperty(AttributeRequiredLevel.None),
MaxLength = 100,
FormatName = StringFormatName.Text,
DisplayName = new Label("Account Name", 1033),
Description = new Label("The primary attribute for the Bank Account entity.", 1033)
}
};
DataverseClient.Execute(createrequest);
Console.WriteLine("The bank account entity has been created.");
for reference: CreateEntityRequest
To Actually create the Columns
you need to execute another request: CreateAttributeRequest