Retrieve Global Option set details – CRM SDK
Below is the sample code to retrieve existing Global Option sets along with Option text & values using RetrieveAllOptionSetsRequest :
var retrieveAllOptionSetsRequest = new RetrieveAllOptionSetsRequest();
RetrieveAllOptionSetsResponse retrieveAllOptionSetsResponse = (RetrieveAllOptionSetsResponse)orgService.Execute(retrieveAllOptionSetsRequest);
if (retrieveAllOptionSetsResponse.OptionSetMetadata.Count() > 0){
StringBuilder sb = new StringBuilder();
foreach (OptionSetMetadataBase optionSetMetadataBase in retrieveAllOptionSetsResponse.OptionSetMetadata){
if (optionSetMetadataBase.OptionSetType != null){
if ((OptionSetType)optionSetMetadataBase.OptionSetType == OptionSetType.Picklist){
OptionSetMetadata optionSetMetadata = (OptionSetMetadata)optionSetMetadataBase;
sb.AppendLine(“OptionSetDisplayName – ” + ((optionSetMetadata.DisplayName.LocalizedLabels.Count > 0) ? optionSetMetadata.DisplayName.LocalizedLabels[0].Label : String.Empty));
sb.AppendLine(“***************************************************”);foreach (OptionMetadata option in optionSetMetadata.Options){
sb.AppendLine(“Option”);
sb.AppendLine(“OptionValue – ” + option.Value.ToString());
sb.AppendLine(“OptionDescription – ” + option.Label.UserLocalizedLabel.Label.ToString());
}
}
else if ((OptionSetType)optionSetMetadataBase.OptionSetType == OptionSetType.Boolean){
BooleanOptionSetMetadata optionSetMetadata = (BooleanOptionSetMetadata)optionSetMetadataBase;
// Start OptionSet Node
//metadataWriter.WriteAttributeString(“OptionSetType”, OptionSetType.Boolean.ToString());
if (optionSetMetadata.DisplayName.LocalizedLabels.Count != 0)
sb.AppendLine(“OptionSetDisplayName – ” + optionSetMetadata.DisplayName.LocalizedLabels[0].Label);
else
sb.AppendLine(“OptionSetDisplayName – ” + “UNDEFINED”);sb.AppendLine(“**************************************************”);
// Writes the TrueOption
sb.AppendLine(“TrueOption”);
sb.AppendLine(“OptionValue – ” + optionSetMetadata.TrueOption.Value.ToString());
sb.AppendLine(“OptionDescription – ” + optionSetMetadata.TrueOption.Label.UserLocalizedLabel.Label.ToString());
sb.AppendLine(“FalseOption”);
sb.AppendLine(“OptionValue – ” + optionSetMetadata.FalseOption.Value.ToString());
sb.AppendLine(“OptionDescription – ” + optionSetMetadata.FalseOption.Label.UserLocalizedLabel.Label.ToString());
}
}
sb.AppendLine(string.Empty);
}Console.WriteLine(sb.ToString());
Output would be
🙂
Leave a Reply Cancel reply
Stats
- 1,581,537 hits
Tweets
- RT @MikeFactorial: Big things are coming to the #CoEStarterKit. So, @ManuelaPichler_ and team are building the tension for the April releas… 3 weeks ago
- New blog post : Boost conversations using GPT in Power Virtual Agent (PVA) rajeevpentyala.com/2023/03/08/pow… 3 weeks ago
- RT @PPDevWeekly: 🔥 Going Live: Power Platform Dev Weekly 155 bit.ly/PPDevWeekly155 This week's cover story by @RajeevPentyala With gre… 3 weeks ago
- RT @caseyburke21: Pipelines is now generally available! Huge congratulations to the team and all who have supported reaching this milestone… 1 month ago
- New blog post : Call Dataverse actions directly in power-fx rajeevpentyala.com/2023/03/01/ste… 1 month ago
Top Posts
- [Code Snippet] Custom Workflow Activity with Input and Output Params
- [Step by Step] Power Apps | Show pop ups in Canvas App
- Power Apps component framework (PCF) - Beginner guide
- Power Automate Cloud Flow | 'Correct to include a valid reference' error
- God Mode - Level Up - Dynamics 365 Chrome Extension
- Set “Created On”,” Created By”, “Modified On”, “Modified By” fields using SDK/Data Import/Plug-in – Dynamics 365
- Power Apps | Business Rule | Set Field Value vs Set Default Value
- Useful JScript syntax's – ADX/Dynamics 365 Portals
- The server was unable to process the request due to an internal error - plugin registration tool
- [Log4net] Exception while reading ConfigurationSettings
Thank you for posting this – saved me hours of work