Export (0) Print
Expand All

UpdateEntity Message (MetadataService)

banner art

[Applies to: Microsoft Dynamics CRM 4.0]

Find the latest SDK documentation: CRM 2015 SDK

Works for all deployment typesWorks online only

Updates the metadata for an entity.

The relevant classes are specified in the following table.



To perform this action, the caller must be a user in the organization for which metadata is requested and must have Write Entity and Write Attribute privileges.

You must publish the changes to the metadata before this change will be visible in the application. For more information see Publishing the Metadata.


The following example shows how to use the UpdateEntity message.

// Create an authentication token.
CrmAuthenticationToken token = new CrmAuthenticationToken();
token.OrganizationName = "AdventureWorksCycle";

// You can use enums.cs from the SDK\Helpers folder to get the enumeration for Active Directory authentication.
token.AuthenticationType = 0; 

// Create the metadata Web service.
MetadataService metadataService = new MetadataService();
metadataService.Url = "http://<servername>:<port>/MSCRMServices/2007/MetadataService.asmx";
metadataService.CrmAuthenticationTokenValue = token;
metadataService.Credentials = System.Net.CredentialCache.DefaultCredentials;
metadataService.PreAuthenticate = true;

// Create the request.
UpdateEntityRequest updateRequest = new UpdateEntityRequest();

// Set the Entity property to an entity retrieved through a RetrieveEntityRequest call.
updateRequest.Entity = contactEntity;
updateRequest.MergeLabels = false;

// Execute the request.
UpdateEntityResponse updateResponse = (UpdateEntityResponse)metadataService.Execute(updateRequest);

// Publish the entity.
// Note:  All customizations must be published before they can be used.
PublishAllXmlRequest publishAllRequest = new PublishAllXmlRequest();
PublishAllXmlResponse publishAllResponse = (PublishAllXmlResponse)metadataService.Execute(publishAllRequest);
[Visual Basic .NET]
' Set up the CRM service.
Dim token As New CrmAuthenticationToken()
' You can use enums.cs from the SDK\Helpers folder to get the enumeration for Active Directory authentication.
token.AuthenticationType = 0
token.OrganizationName = "AdventureWorksCycle";

// Create the metadata Web service.
Dim metadataService As New MetadataService ()
metadataService.Url = "http://<servername>:<port>/mscrmservices/2007/MetadataService.asmx";
metadataService.CrmAuthenticationTokenValue = token;
metadataService.Credentials = System.Net.CredentialCache.DefaultCredentials
metadataService.PreAuthenticate = true;

' Create the request.
Dim entityRequest As New RetrieveEntityRequest()
entityRequest.RetrieveAsIfPublished = True
entityRequest.LogicalName = EntityName.contact.ToString()
entityRequest.EntityItems = EntityItems.All

Dim entityResponse As RetrieveEntityResponse = CType(metadataService.Execute(entityRequest), RetrieveEntityResponse)

' Rename contact to client.
Dim contactEntity As EntityMetadata = entityResponse.EntityMetadata
contactEntity.DisplayName = Microsoft.Crm.Sdk.Utility.CrmServiceUtility.CreateSingleLabel("Client", 1033)
contactEntity.DisplayCollectionName = Microsoft.Crm.Sdk.Utility.CrmServiceUtility.CreateSingleLabel("Clients", 1033)

See Also



© 2010 Microsoft Corporation. All rights reserved.

© 2015 Microsoft