Export (0) Print
Expand All

UpdateAttribute Message (MetadataService)

banner art

[Applies to: Microsoft Dynamics CRM 4.0]

Works for all deployment typesWorks online only

Updates the metadata for an attribute.

The relevant classes are specified in the following table.

TypeClass
RequestUpdateAttributeRequest
ResponseUpdateAttributeResponse

Remarks

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

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

Example

The following example shows how to use the UpdateAttribute message.

[C#]
// 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;

// Update an attribute retrieved via RetrieveAttributeRequest
UpdateAttributeRequest updateRequest = new UpdateAttributeRequest();
updateRequest.Attribute = retrievedAttributeMetadata;
updateRequest.EntityName = EntityName.contact.ToString();
updateRequest.MergeLabels = false;

// Execute the request
UpdateAttributeResponse updateResponse = (UpdateAttributeResponse)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 attributeRequest As New RetrieveAttributeRequest()
attributeRequest.EntityLogicalName = EntityName.contact.ToString()
attributeRequest.LogicalName = "fullname"
attributeRequest.RetrieveAsIfPublished = True

' Execute the request.
Dim attributeResponse As RetrieveAttributeResponse = CType(metadataService.Execute(attributeRequest), RetrieveAttributeResponse)

' Modify the retrieved attribute.
Dim retrievedAttributeMetadata As AttributeMetadata = attributeResponse.AttributeMetadata
retrievedAttributeMetadata.DisplayName = Microsoft.Crm.Sdk.Utility.CrmServiceUtility.CreateSingleLabel("My Display Name", 1033)

See Also

Concepts

Reference


© 2010 Microsoft Corporation. All rights reserved.


Show:
© 2014 Microsoft