Hi,
in custom workflow activity I use it to retrieve entities:
string fetchXMl = @"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>
<entity name='opportunity'>
<attribute name='new_optionsetattribute' />
<filter type='and'>
<condition attribute='statecode' operator='eq' value='0' />
<condition attribute='statuscode' operator='eq' value='1' />
</filter>
</entity>
</fetch>";
EntityCollection ents = service.RetrieveMultiple(new FetchExpression(fetchXMl));
Next in code I try to get, a optionset value label;
foreach (var ent in ents.Entities)
{
if (enti.Attributes.Contains("new_optionsetattribute"))
{
oppValue = ((OptionSetValue)enti["new_optionsetattribute"]).Value;
prospectLevelText = GetOptionsSetTextOnValue(service, "opportunity", "new_optionsetattribute", oppValue);
--------------OR-----------------------
if (enti.FormattedValues["new_optionsetattribute"] != null)
prospectLevelText = enti.FormattedValues["new_optionsetattribute"];
}
}
public string GetOptionsSetTextOnValue(string entityName, string attributeName, int optionSetValue)
{
string optionsetLabel = String.Empty;
try
{
RetrieveEntityRequest retrieveDetails = new RetrieveEntityRequest
{
EntityFilters = EntityFilters.All,
LogicalName = entityName
};
RetrieveEntityResponse retrieveEntityResponseObj = (RetrieveEntityResponse)service.Execute(retrieveDetails);
EntityMetadata metadata = retrieveEntityResponseObj.EntityMetadata;
PicklistAttributeMetadata picklistMetadata = metadata.Attributes.FirstOrDefault(attribute =>
String.Equals(attribute.LogicalName, attributeName, StringComparison.OrdinalIgnoreCase)) as PicklistAttributeMetadata;
OptionSetMetadata options = picklistMetadata.OptionSet;
IList<OptionMetadata> OptionsList = (from o in options.Options
where o.Value.Value == optionSetValue
select o).ToList();
if (OptionsList != null && OptionsList.Count != 0)
{
optionsetLabel = (OptionsList.First()).Label.UserLocalizedLabel.Label;
}
}
catch (Exception ex)
{
throw new InvalidPluginExecutionException(ex.Message);
}
return optionsetLabel;
Unfortunatelly any of this doesent work.
How to get a optionset value label from custom OptionSet attribute in custom workflow activity ?
in custom workflow activity I use it to retrieve entities:
string fetchXMl = @"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>
<entity name='opportunity'>
<attribute name='new_optionsetattribute' />
<filter type='and'>
<condition attribute='statecode' operator='eq' value='0' />
<condition attribute='statuscode' operator='eq' value='1' />
</filter>
</entity>
</fetch>";
EntityCollection ents = service.RetrieveMultiple(new FetchExpression(fetchXMl));
Next in code I try to get, a optionset value label;
foreach (var ent in ents.Entities)
{
if (enti.Attributes.Contains("new_optionsetattribute"))
{
oppValue = ((OptionSetValue)enti["new_optionsetattribute"]).Value;
prospectLevelText = GetOptionsSetTextOnValue(service, "opportunity", "new_optionsetattribute", oppValue);
--------------OR-----------------------
if (enti.FormattedValues["new_optionsetattribute"] != null)
prospectLevelText = enti.FormattedValues["new_optionsetattribute"];
}
}
public string GetOptionsSetTextOnValue(string entityName, string attributeName, int optionSetValue)
{
string optionsetLabel = String.Empty;
try
{
RetrieveEntityRequest retrieveDetails = new RetrieveEntityRequest
{
EntityFilters = EntityFilters.All,
LogicalName = entityName
};
RetrieveEntityResponse retrieveEntityResponseObj = (RetrieveEntityResponse)service.Execute(retrieveDetails);
EntityMetadata metadata = retrieveEntityResponseObj.EntityMetadata;
PicklistAttributeMetadata picklistMetadata = metadata.Attributes.FirstOrDefault(attribute =>
String.Equals(attribute.LogicalName, attributeName, StringComparison.OrdinalIgnoreCase)) as PicklistAttributeMetadata;
OptionSetMetadata options = picklistMetadata.OptionSet;
IList<OptionMetadata> OptionsList = (from o in options.Options
where o.Value.Value == optionSetValue
select o).ToList();
if (OptionsList != null && OptionsList.Count != 0)
{
optionsetLabel = (OptionsList.First()).Label.UserLocalizedLabel.Label;
}
}
catch (Exception ex)
{
throw new InvalidPluginExecutionException(ex.Message);
}
return optionsetLabel;
Unfortunatelly any of this doesent work.
How to get a optionset value label from custom OptionSet attribute in custom workflow activity ?