Get OptionSet Lable Value
function call :
GetOptionsSetTextOnValue(service, Opportunity.EntityLogicalName, “opportunityratingcode”, ((OptionSetValue)_entityOpp.Attributes["opportunityratingcode"]).Value);
function call :
GetOptionsSetTextOnValue(service, Opportunity.EntityLogicalName, “opportunityratingcode”, ((OptionSetValue)_entityOpp.Attributes["opportunityratingcode"]).Value);
private string GetOptionsSetTextOnValue(IOrganizationService service, string entityName, string attributeName, int selectedValue) { RetrieveAttributeRequest retrieveAttributeRequest = new RetrieveAttributeRequest { EntityLogicalName = entityName, LogicalName = attributeName, RetrieveAsIfPublished = true }; // Execute the request. RetrieveAttributeResponse retrieveAttributeResponse = (RetrieveAttributeResponse)service.Execute(retrieveAttributeRequest); // Access the retrieved attribute. Microsoft.Xrm.Sdk.Metadata.PicklistAttributeMetadata retrievedPicklistAttributeMetadata = (Microsoft.Xrm.Sdk.Metadata.PicklistAttributeMetadata) retrieveAttributeResponse.AttributeMetadata;// Get the current options list for the retrieved attribute. OptionMetadata[] optionList = retrievedPicklistAttributeMetadata.OptionSet.Options.ToArray(); string selectedOptionLabel = string.Empty; foreach (OptionMetadata oMD in optionList) { if (oMD.Value == selectedValue) { selectedOptionLabel = oMD.Label.UserLocalizedLabel.Label; } } return selectedOptionLabel; }Get State Lable Value
private string GetStateTextOnValue(IOrganizationService service, string entityName, string attributeName, int selectedValue) { RetrieveAttributeRequest retrieveAttributeRequest = new RetrieveAttributeRequest { EntityLogicalName = entityName, LogicalName = attributeName, RetrieveAsIfPublished = true }; // Execute the request. RetrieveAttributeResponse retrieveAttributeResponse = (RetrieveAttributeResponse)service.Execute(retrieveAttributeRequest); // Access the retrieved attribute. AttributeMetadata attrMetadata = (AttributeMetadata)retrieveAttributeResponse.AttributeMetadata;// Get the current options list for the retrieved attribute. // Cast the AttributeMetadata to StatusAttribute data StateAttributeMetadata statusAttrMetadata = (StateAttributeMetadata)attrMetadata; string selectedOptionLabel = string.Empty; foreach( StateOptionMetadata statusMeta in statusAttrMetadata.OptionSet.Options) { if (statusMeta.Value == selectedValue) { selectedOptionLabel = statusMeta.Label.UserLocalizedLabel.Label; } } return selectedOptionLabel; }Get Status Lable Value
private string GetStatusTextOnValue(IOrganizationService service, string entityName, string attributeName, int selectedValue) { RetrieveAttributeRequest retrieveAttributeRequest = new RetrieveAttributeRequest { EntityLogicalName = entityName, LogicalName = attributeName, RetrieveAsIfPublished = true }; // Execute the request. RetrieveAttributeResponse retrieveAttributeResponse = (RetrieveAttributeResponse)service.Execute(retrieveAttributeRequest); // Access the retrieved attribute. AttributeMetadata attrMetadata = (AttributeMetadata)retrieveAttributeResponse.AttributeMetadata;// Get the current options list for the retrieved attribute. // Cast the AttributeMetadata to StatusAttribute data StatusAttributeMetadata statusAttrMetadata = (StatusAttributeMetadata)attrMetadata; string selectedOptionLabel = string.Empty; foreach (StatusOptionMetadata statusMeta in statusAttrMetadata.OptionSet.Options) { if (statusMeta.Value == selectedValue) { selectedOptionLabel = statusMeta.Label.UserLocalizedLabel.Label; } } return selectedOptionLabel; }
No comments:
Post a Comment