Creare un'entità personalizzata
Data di pubblicazione: novembre 2016
Si applica a: Dynamics CRM 2015
In questo argomento viene descritto come creare un'entità di proprietà dell'utente personalizzata denominata Bank Account e come aggiungere ad essa quattro tipi di attributi.
È inoltre possibile creare le entità personalizzate di proprietà dell'organizzazione.Ulteriori informazioni:Proprietà delle entità
Nota
Non sarà possibile visualizzare questa entità nella navigazione dell'applicazione a meno che le proprietà delle entità non vengano modificate nel set in cui sono impostate sulle impostazioni delle aree in cui viene visualizzata l'entità.
In questo argomento
Creare un'entità personalizzata
Aggiungere un attributo di tipo stringa all'entità personalizzata
Aggiungere un attributo di tipo Money all'entità personalizzata
Aggiungere un attributo di tipo DateTime all'entità personalizzata
Aggiungere un attributo di tipo lookup all'entità personalizzata
Creare un'entità personalizzata
Nell'esempio seguente viene utilizzato CreateEntityRequest per creare l'entità StringAttributeMetadata e l'entità PrimaryAttribute.
Il valore di _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)
}
};
_serviceProxy.Execute(createrequest);
Console.WriteLine("The bank account entity has been created.");
Dim createrequest As CreateEntityRequest = New CreateEntityRequest With {
.Entity = New EntityMetadata With {
.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},
.PrimaryAttribute = New StringAttributeMetadata With {
.SchemaName = "new_accountname",
.RequiredLevel = New AttributeRequiredLevelManagedProperty(AttributeRequiredLevel.None),
.MaxLength = 100,
.Format = StringFormat.Text,
.DisplayName = New Label("Account Name", 1033),
.Description = New Label("The primary attribute for the Bank Account entity.", 1033)
}
}
'Define the entity
' Define the primary attribute for the entity
_serviceProxy.Execute(createrequest)
Console.WriteLine("The bank account entity has been created.")
Aggiungere un attributo di tipo stringa all'entità personalizzata
Nell'esempio seguente viene aggiunto un attributo StringAttributeMetadata all'entità Bank Account.
CreateAttributeRequest createBankNameAttributeRequest = new CreateAttributeRequest
{
EntityName = _customEntityName,
Attribute = new StringAttributeMetadata
{
SchemaName = "new_bankname",
RequiredLevel = new AttributeRequiredLevelManagedProperty(AttributeRequiredLevel.None),
MaxLength = 100,
FormatName = StringFormatName.Text,
DisplayName = new Label("Bank Name", 1033),
Description = new Label("The name of the bank.", 1033)
}
};
_serviceProxy.Execute(createBankNameAttributeRequest);
Dim createBankNameAttributeRequest As CreateAttributeRequest = New CreateAttributeRequest With {
.EntityName = _customEntityName,
.Attribute = New StringAttributeMetadata With {
.SchemaName = "new_bankname",
.RequiredLevel = New AttributeRequiredLevelManagedProperty(AttributeRequiredLevel.None),
.MaxLength = 100,
.Format = StringFormat.Text,
.DisplayName = New Label("Bank Name", 1033),
.Description = New Label("The name of the bank.", 1033)
}
}
_serviceProxy.Execute(createBankNameAttributeRequest)
Aggiungere un attributo di tipo Money all'entità personalizzata
Nell'esempio seguente viene aggiunto un attributo MoneyAttributeMetadata all'entità Bank Account.
CreateAttributeRequest createBalanceAttributeRequest = new CreateAttributeRequest
{
EntityName = _customEntityName,
Attribute = new MoneyAttributeMetadata
{
SchemaName = "new_balance",
RequiredLevel = new AttributeRequiredLevelManagedProperty(AttributeRequiredLevel.None),
PrecisionSource = 2,
DisplayName = new Label("Balance", 1033),
Description = new Label("Account Balance at the last known date", 1033),
}
};
_serviceProxy.Execute(createBalanceAttributeRequest);
Dim createBalanceAttributeRequest As CreateAttributeRequest = New CreateAttributeRequest With {
.EntityName = _customEntityName,
.Attribute = New MoneyAttributeMetadata With {
.SchemaName = "new_balance",
.RequiredLevel = New AttributeRequiredLevelManagedProperty(AttributeRequiredLevel.None),
.PrecisionSource = 2,
.DisplayName = New Label("Balance", 1033),
.Description = New Label("Account Balance at the last known date", 1033)
}
}
_serviceProxy.Execute(createBalanceAttributeRequest)
Aggiungere un attributo di tipo DateTime all'entità personalizzata
Nell'esempio seguente viene aggiunto un attributo DateTimeAttributeMetadata all'entità Bank Account.
CreateAttributeRequest createCheckedDateRequest = new CreateAttributeRequest
{
EntityName = _customEntityName,
Attribute = new DateTimeAttributeMetadata
{
SchemaName = "new_checkeddate",
RequiredLevel = new AttributeRequiredLevelManagedProperty(AttributeRequiredLevel.None),
Format = DateTimeFormat.DateOnly,
DisplayName = new Label("Date", 1033),
Description = new Label("The date the account balance was last confirmed", 1033)
}
};
_serviceProxy.Execute(createCheckedDateRequest);
Console.WriteLine("An date attribute has been added to the bank account entity.");
Dim createCheckedDateRequest As CreateAttributeRequest = New CreateAttributeRequest With {
.EntityName = _customEntityName,
.Attribute = New DateTimeAttributeMetadata With {
.SchemaName = "new_checkeddate",
.RequiredLevel = New AttributeRequiredLevelManagedProperty(AttributeRequiredLevel.None),
.Format = DateTimeFormat.DateOnly,
.DisplayName = New Label("Date", 1033),
.Description = New Label("The date the account balance was last confirmed", 1033)
}
}
_serviceProxy.Execute(createCheckedDateRequest)
Console.WriteLine("An date attribute has been added to the bank account entity.")
Aggiungere un attributo di tipo lookup all'entità personalizzata
Nell'esempio seguente viene utilizzato CreateOneToManyRequest per creare una relazione uno-a-molti con l'entità Contact in modo da aggiungere un attributo all'entità LookupAttributeMetadataBank Account.
CreateOneToManyRequest req = new CreateOneToManyRequest()
{
Lookup = new LookupAttributeMetadata()
{
Description = new Label("The owner of the bank account", 1033),
DisplayName = new Label("Account Owner", 1033),
LogicalName = "new_parent_contactid",
SchemaName = "New_Parent_ContactId",
RequiredLevel = new AttributeRequiredLevelManagedProperty(AttributeRequiredLevel.ApplicationRequired)
},
OneToManyRelationship = new OneToManyRelationshipMetadata()
{
AssociatedMenuConfiguration = new AssociatedMenuConfiguration()
{
Behavior = AssociatedMenuBehavior.UseCollectionName,
Group = AssociatedMenuGroup.Details,
Label = new Label("Bank Accounts", 1033),
Order = 10000
},
CascadeConfiguration = new CascadeConfiguration()
{
Assign = CascadeType.Cascade,
Delete = CascadeType.Cascade,
Merge = CascadeType.Cascade,
Reparent = CascadeType.Cascade,
Share = CascadeType.Cascade,
Unshare = CascadeType.Cascade
},
ReferencedEntity = Contact.EntityLogicalName,
ReferencedAttribute = "contactid",
ReferencingEntity = _customEntityName,
SchemaName = "new_contact_new_bankaccount"
}
};
_serviceProxy.Execute(req);
Dim req As New CreateOneToManyRequest() With {
.Lookup = New LookupAttributeMetadata() With {
.Description = New Label("The owner of the bank account", 1033),
.DisplayName = New Label("Account Owner", 1033),
.LogicalName = "new_parent_contactid",
.SchemaName = "New_Parent_ContactId",
.RequiredLevel = New AttributeRequiredLevelManagedProperty(AttributeRequiredLevel.ApplicationRequired)},
.OneToManyRelationship = New OneToManyRelationshipMetadata() With {
.AssociatedMenuConfiguration = New AssociatedMenuConfiguration() With {
.Behavior = AssociatedMenuBehavior.UseCollectionName,
.Group = AssociatedMenuGroup.Details,
.Label = New Label("Bank Accounts", 1033),
.Order = 10000},
.CascadeConfiguration = New CascadeConfiguration() With {
.Assign = CascadeType.Cascade,
.Delete = CascadeType.Cascade,
.Merge = CascadeType.Cascade,
.Reparent = CascadeType.Cascade,
.Share = CascadeType.Cascade,
.Unshare = CascadeType.Cascade},
.ReferencedEntity = Contact.EntityLogicalName,
.ReferencedAttribute = "contactid",
.ReferencingEntity = _customEntityName,
.SchemaName = "new_contact_new_bankaccount"
}
}
_serviceProxy.Execute(req)
Vedere anche
CreateEntityRequest
Utilizzare il codice di esempio e dell'helper
Personalizzare i metadati dell'entità
Quali entità sono personalizzabili?
Recuperare, aggiornare ed eliminare entità.
Creare e aggiornare un'entità che è possibile inviare per posta elettronica
Creare un'entità di tipo impegno personalizzata
Modificare le icone per un'entità
Modificare i messaggi per un'entità
© 2017 Microsoft. Tutti i diritti sono riservati. Copyright