Option set is a type of field in an Entity. It shows set of Options. If an Option Set field is taken in the form it will be displayed as a drop-down list control. Sometimes we call Option sets as Pick lists. For Example in CRM4.0 we called Option set as Pick list.
Option Sets are two types
1) Global Option set
2) Local Option set
Global Option Set: Global Option Sets are used in one or more than one Entity. User can use it globally. If same option set field is required in two entities then there is no need of creating two option sets in two entities as only one option set can be created Globally and an user will be able to use it. This is the main use of Global Option set.
Local Option Set: A Local Option Set is used within the Entity itself. This option set cannot be used for the other entity in the CRM.
How to Create Global Option Set:
Path: Go to > Microsoft CRM Home Page-> Main Settings – >Customizations – >Customize the System –> Default Solution- >Option Sets
- In the above image an “Option Sets” is seen in default solution Components.
- Click on Option Sets a pop window appears as follows.
- In the above image Click on “New”.
- After clicking on “New” button a popup window appears, all the required fields in that popup window need to be filled. See the below image
- In the above window there are four fields that are required to be filled
1) Display Name
2) Name
3) Label
4) Value
- After filling all those details click on “Save” and publish it.
- It creates a new Option set. Now it can be used in any Entity in MS CRM.
- A newly created Global option set is seen as below.
How to use Global Option Set in Entities:
- Go to default solution –> click on Entities select any entity (Ex: Account) – >click on fields and create a new Option set field.
- Click on “New” button and a pop window appears as below.
- In the above image an existing Option Set is used i.e. Global Option Set.
- In the above image there is a field called “Use Existing Option Set” with two radio buttons displaying in red color.
- Click on “Yes”. An “option set” with the combo box will be displayed. It contains all the Global Options Sets. Existing Global Option Set can be edited by using “Edit” button.
- A required Global option set is selected from the drop down.In the above image we “Test Global Option set” is set as an option set for Account Entity.
- That means “Test Account Option set” contains all the set of Options of the “Test Global Option Set”.
- Finally click on “Save and Close” and add this option set field in the Account form and click on publish customizations.
- An Option set can be seen in the record of Account Entity .
- In the above image “TestAccountOptionset” Option set field contains three options i.e test1,test2,test3
- These three options belong to “Test Global Option Set”. In this way a Global Option Sets can be used as a set of Options in a required Entity’s Option Set options.
Create a Global Option Set By using C# Coding :
using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using System.ServiceModel.Description;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Client;
using Microsoft.Xrm.Sdk.Metadata;
using Microsoft.Xrm.Sdk.Query;
using Microsoft.Xrm.Sdk.Discovery;
using Microsoft.Xrm.Sdk.Messages;
namespace GlobalOptionset
{
public class GlobalOptionSetCreation
{
IOrganizationService service = ServiceHelper.ServiceProxy;
private const int _languageCode = 1033;
private const String _optionSetName = "mtcem_testglobaloptionset";
public void TestGlobalOptionSet()
{
try
{
// Define the option set to create.
OptionSetMetadata setupOptionSetMetadata = new OptionSetMetadata()
{
Name = _optionSetName,
DisplayName = new Label("Test Global Option Set", _languageCode),
Description = new Label("An Example for Creating Global Option Set", _languageCode),
IsGlobal = true,
OptionSetType = OptionSetType.Picklist,
// Give the list of Options
Options =
{
new OptionMetadata(new Label("Test1", _languageCode), null ),
new OptionMetadata(new Label("Test2", _languageCode), null ),
new OptionMetadata(new Label("Test3", _languageCode), null )
}
};
CreateOptionSetRequest createOptionSetRequest = new CreateOptionSetRequest
{
OptionSet = setupOptionSetMetadata
};
service.Execute(createOptionSetRequest);
Console.WriteLine("Global Option Set is created");
}
// Catch any service fault exceptions that Microsoft Dynamics CRM throws.
catch (FaultException<Microsoft.Xrm.Sdk.OrganizationServiceFault>)
{
throw;
}
}
}
}
THANK YOU