Share via


Helper code: Enumerations for option sets

 

Applies To: Dynamics 365 (online), Dynamics 365 (on-premises), Dynamics CRM 2016, Dynamics CRM Online

The SDK download package includes an extension to the CrmSvcUtil code generation tool that you can use to generate enumerations for all option set values including global option sets, picklist, state, and status values. For more information, see Sample extension to generate enumerations for option sets. In addition, it includes a helper code file that contains the enumerations generated for all out-of-the-box values. These enumerations can be used in your code by adding the file SampleCode\CS\HelperCode\OptionSets.cs or SampleCode\VB\HelperCode\OptionSets.vb to your project.

Each numeration can be used to test or set the value for a property. Typically this property is an entity attribute but there are a few that are used for other properties.

Usage Example

The following example shows how to use one of these enumerations to set a value in the Account entity.


// Instantiate an account object. Note the use of the option set enumerations defined
// in OptionSets.cs.
Account account = new Account { Name = "Fourth Coffee" };
account.AccountCategoryCode = new OptionSetValue((int)AccountAccountCategoryCode.PreferredCustomer);
account.CustomerTypeCode = new OptionSetValue((int)AccountCustomerTypeCode.Investor);

// Create an account record named Fourth Coffee.
// Save the record reference so we can delete it during cleanup later.
Guid accountId = service.Create(account);


' Instantiate an account object. Note the use of the option set enumerations defined in OptionSets.vb.
' See the Entity Metadata topic in the SDK documentation to determine 
' which attributes must be set for each entity.
Dim account_Renamed As Account = New Account With {.Name = "Fourth Coffee"}
account_Renamed.AccountCategoryCode = New OptionSetValue(CInt(AccountAccountCategoryCode.PreferredCustomer))
account_Renamed.CustomerTypeCode = New OptionSetValue(CInt(AccountCustomerTypeCode.Investor))

' Create an account record named Fourth Coffee.
_accountId = _serviceProxy.Create(account_Renamed)

See Also

Use the sample and helper code
Helper code: ServerConnection class
Helper code: DeviceIdManager class
Helper code: SystemUserProvider class
Sample extension to generate enumerations for option sets
Global option set metadata values
Run a simple program using Microsoft Dynamics 365 web services

Microsoft Dynamics 365

© 2016 Microsoft. All rights reserved. Copyright