UpdateOptionValue Message (MetadataService)

banner art

[Applies to: Microsoft Dynamics CRM 4.0]

Find the latest SDK documentation: CRM 2015 SDK

Works for all deployment types Works online only

Updates the metadata for an option value.

The relevant classes are specified in the following table.

Type Class
Request UpdateOptionValueRequest
Response UpdateOptionValueResponse

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 UpdateOptionValue 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;

// Create a new picklist label.
MetadataServiceSdk.CrmLabel newCrmLabel = new MetadataServiceSdk.CrmLabel();
MetadataServiceSdk.CrmNumber langCode = new MetadataServiceSdk.CrmNumber();
MetadataServiceSdk.LocLabel englishLabel = new MetadataServiceSdk.LocLabel();

// Use the US English language code.
langCode.Value = 1033; 
englishLabel.LanguageCode = langCode;

// Rename existing "Bill To" label text to "Billing".
englishLabel.Label = "Billing";
newCrmLabel.LocLabels = new MetadataServiceSdk.LocLabel[] { englishLabel };

// Create a request.
UpdateOptionValueRequest updateRequest = new UpdateOptionValueRequest();

// Update an existing picklist.
updateRequest.AttributeLogicalName = "address1_addresstypecode";
updateRequest.EntityLogicalName = EntityName.contact.ToString();
updateRequest.MergeLabels = false;
updateRequest.Value = 1;
updateRequest.Label = newCrmLabel;

// Send the message.
UpdateOptionValueResponse updateResponse = (UpdateOptionValueResponse)metadataService.Execute(updateRequest);

// Publish the new custom 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 a new picklist label.
Dim newCrmLabel As New MetadataServiceSdk.CrmLabel()
Dim langCode As New MetadataServiceSdk.CrmNumber()
Dim englishLabel As New MetadataServiceSdk.LocLabel()

' Use the US English language code.
langCode.Value = 1033
englishLabel.LanguageCode = langCode

' Rename existing "Bill To" label text to "Billing".
englishLabel.Label = "Billing"
newCrmLabel.LocLabels = New MetadataServiceSdk.LocLabel() { englishLabel }

' Create a request.
Dim updateRequest As New UpdateOptionValueRequest()

' Update an existing picklist.
updateRequest.AttributeLogicalName = "address1_addresstypecode"
updateRequest.EntityLogicalName = EntityName.contact.ToString()
updateRequest.MergeLabels = False
updateRequest.Value = 1
updateRequest.Label = newCrmLabel

' Send the message.
Dim updateResponse As UpdateOptionValueResponse = CType(metadataService.Execute(updateRequest), UpdateOptionValueResponse)

' Publish the new custom entity.
' Note: All customizations must be published before they can be used.
Dim publishAllRequest As New PublishAllXmlRequest()
Dim publishAllResponse As PublishAllXmlResponse = CType(metadataService.Execute(publishAllRequest), PublishAllXmlResponse)

See Also

Concepts

Reference

© 2010 Microsoft Corporation. All rights reserved.