locked
Issue in retrieving Optenset text using FormattedValues RRS feed

  • Question

  • I have a plugin, registered on create of record in post operation. From PluginContext, I got that entity record and tried to read the Optionset text using formattedvalues. But Formattedvalues for that field is not available though that optionset field has value. Below is the sample code snippet that I have used.

    EntityrecAppContract = context.InputParameters["Target"] asEntity;

    recAppContract.Contains(

    "vc_allocationtype") ? recAppContract.FormattedValues["vc_allocationtype"] : string.Empty;

    Earlier this code was working fine. But it is throwing error "the given key was not present in the dictionary" now.

    Please suggest some solution for this issue.

    Thanks

    Wednesday, April 15, 2015 2:23 PM

Answers

  • I don't think the Target InputParameter has ever populated FormattedValues, as this would be extra performance overhead. Maybe your code in the other plugin is slightly different - e.g. it may use entity images to get the data (which I think do populate FormattedValues), or a separate Retrieve

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

    Thursday, April 16, 2015 9:27 AM
    Moderator

All replies

  • Hello,

    Use RetrieveAttributeRequest to retrieve required optionset attribute and get label from it.


    Dynamics CRM MVP
    My blog

    Wednesday, April 15, 2015 2:40 PM
    Moderator
  • The Target InputParameter does not include any data within FormattedValues. You can get the data through the Crm metadata, as Andrii suggests above, or you could do an additional Retrieve of the record (though this depends on whether the plugin runs on a pre or post step), which would return data in FormattedValues

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

    Wednesday, April 15, 2015 9:54 PM
    Moderator
  • I agree that we can use RetrieveAttributeRequest  instead. But What I'm wondering about is it was working fine earlier. And still in my other entity plug-in, it is giving the formatted values of OptionSet from the Context which is also registered on Create- Post operation.
    Thursday, April 16, 2015 6:41 AM
  • I don't think the Target InputParameter has ever populated FormattedValues, as this would be extra performance overhead. Maybe your code in the other plugin is slightly different - e.g. it may use entity images to get the data (which I think do populate FormattedValues), or a separate Retrieve

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

    Thursday, April 16, 2015 9:27 AM
    Moderator
  • Thank you David :) By Using Post Image, I got the Formatted values of OptionSet
    Tuesday, May 26, 2015 10:45 AM