microsoft / PowerApps-Samples

Sample code for Power Apps, including Dataverse, model-driven apps, canvas apps, Power Apps component framework, portals, and AI Builder.

Home Page:https://docs.microsoft.com/powerapps

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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...
image

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

@murati
Sorry for the delay in responding.
If you have an issue with any of our published samples, please raise an issue here.
But we can't provide technical support through this forum.