web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

How to get option set text from a pre image for plugins in MSCRM?

(0) ShareShare
ReportReport
Posted on by 592

I am able to get the value from the preimage/post image but not the label for the option set. 

preStatuscode = PreImage.GetAttributeValue<OptionSetValue>("statuscode");

*This post is locked for comments

I have the same question (0)
  • Alex Fun Wei Jie Profile Picture
    33,628 on at

    Hi,

    you need access the metadata in order to get the label. You can refer below post to get the code.

    stackoverflow.com/.../get-the-string-value-from-optionsetvalue-in-crm-plugin

  • Shahbaaz Ansari Profile Picture
    6,211 on at

    Hi Prasad,

    use below method to get the option-set label in plugin,

    public static string GetOptionSetValueLabel(string entityName, string fieldName, int optionSetValue, IOrganizationService service)
    
       {
    
           var attReq = new RetrieveAttributeRequest();
    
           attReq.EntityLogicalName = entityName;
    
           attReq.LogicalName = fieldName;
    
           attReq.RetrieveAsIfPublished = true;
    
           var attResponse = (RetrieveAttributeResponse)service.Execute(attReq);
    
           var attMetadata = (EnumAttributeMetadata)attResponse.AttributeMetadata;
    
           return attMetadata.OptionSet.Options.Where(x => x.Value == optionSetValue).FirstOrDefault().Label.UserLocalizedLabel.Label;
    
       }

    Also you can refer 

    https://community.dynamics.com/crm/b/mshelp/archive/2012/06/12/get-optionset-text-from-value-or-value-from-text

    Best Regards,

    Shahbaaz

  • Verified answer
    Shidin Haridas Profile Picture
    3,499 on at

    Check if you can find the label value under the 'FormattedValues' of the PreImages.

    Let me know if you need more details.

  • MS CRM DYNAMICS Profile Picture
    592 on at

    gCRStatus = PostImg.Contains("mms_gcrstatus") ? PostImg.FormattedValues["mms_gcrstatus"] : string.Empty;

    this worked thank you.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans