Pass in optionsetvalue to workflow activity not working RRS feed

  • Question

  • Hi All I am trying to pass in a global optionsetvalue to a workflow activity but keep getting errors:


            [Input("Process type")]
            [AttributeTarget("bi_workflowprocessmapping", "bi_processtype")]
            public InOutArgument<OptionSetValue> ProcessTypeOS { get; set; }

    I am passing in a static value also, not a dynamic value so the field should not be null

    Getting the following error

    Unhandled Exception: Microsoft.Xrm.Sdk.InvalidPluginExecutionException: Exception CloseAllCasesForOrgProcessType Activity: System.ServiceModel.FaultException`1[Microsoft.Xrm.Sdk.OrganizationServiceFault]: An exception System.FormatException was thrown while trying to convert input value 'Microsoft.Xrm.Sdk.OptionSetValue' to attribute 'bi_workflowprocessmapping.bi_processtype'. Expected type of attribute value: System.Int32. Exception raised: Input string was not in a correct format. (Fault Detail is equal to Microsoft.Xrm.Sdk.OrganizationServiceFault).

    Really not sure where to go from here. Please help,




    • Edited by nicko2009 Tuesday, December 1, 2015 3:59 PM
    Tuesday, December 1, 2015 3:58 PM

All replies

  • HI nick,

    try to pass an Int32 as follows

    public InOutArgument<Int32> ProcessTypeOS { get; set; }

    and pass the integer value of the optionset.

    Damian Sinay

    Tuesday, December 1, 2015 4:20 PM
  • Your code does look correct, as parameter should be defined as

    public InOutArgument<OptionSetValue> ProcessTypeOS { get; set; }

    Is the error thrown within your code, or before it gets to your code ? To test this, check if you still get an error even if your code never uses the attribute.

    Have you published the option set - I could imagine you getting the 'Input string was not in a correct format' error if it's not been published. Also, if you use language packs, I'd check you have labels for this option set for all languages

    Microsoft CRM MVP - http://mscrmuk.blogspot.com/ http://www.excitation.co.uk

    Tuesday, December 1, 2015 5:02 PM
  • Hi Nick,

     Is your parameter inOut or in? Please try the following?

    // Declaration
    [Input("Process type")]
    [AttributeTarget("bi_workflowprocessmapping", "bi_processtype")]
    public InArgument<OptionSetValue> ProcessTypeOS { get; set; }
    //Inside protected override void Execute(CodeActivityContext executionContext)
    var processTypeOS = this.ProcessTypeOS.Get<OptionSetValue>(executionContext);
    if (processTypeOS.Value == 100000000)



    Tuesday, December 1, 2015 11:01 PM
  • To get the text value you can user following method
    public static string GetoptionsetText(string entityName, string attributeName, int optionSetValue, IOrganizationService service)
                string AttributeName = attributeName;
                string EntityLogicalName = entityName;
                RetrieveEntityRequest retrieveDetails = new RetrieveEntityRequest
                    EntityFilters = EntityFilters.All,
                    LogicalName = EntityLogicalName
                RetrieveEntityResponse retrieveEntityResponseObj = (RetrieveEntityResponse)service.Execute(retrieveDetails);
                Microsoft.Xrm.Sdk.Metadata.EntityMetadata metadata = retrieveEntityResponseObj.EntityMetadata;
                Microsoft.Xrm.Sdk.Metadata.PicklistAttributeMetadata picklistMetadata = metadata.Attributes.FirstOrDefault(attribute => String.Equals(attribute.LogicalName, attributeName, StringComparison.OrdinalIgnoreCase)) as Microsoft.Xrm.Sdk.Metadata.PicklistAttributeMetadata;
                Microsoft.Xrm.Sdk.Metadata.OptionSetMetadata options = picklistMetadata.OptionSet;
                IList<OptionMetadata> OptionsList = (from o in options.Options
                                                     where o.Value.Value == optionSetValue
                                                     select o).ToList();
                string optionsetLabel = (OptionsList.First()).Label.UserLocalizedLabel.Label;
                return optionsetLabel;

    Regards Faisal

    Wednesday, December 2, 2015 11:40 AM