Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

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

Posted on by 580

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

  • MS CRM DYNAMICS Profile Picture
    MS CRM DYNAMICS 580 on at
    RE: How to get option set text from a pre image for plugins in MSCRM?

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

    this worked thank you.

  • Verified answer
    Shidin Haridas Profile Picture
    Shidin Haridas 3,497 on at
    RE: How to get option set text from a pre image for plugins in MSCRM?

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

    Let me know if you need more details.

  • Shahbaaz Ansari Profile Picture
    Shahbaaz Ansari 6,203 on at
    RE: How to get option set text from a pre image for plugins in MSCRM?

    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

  • Alex Fun Wei Jie Profile Picture
    Alex Fun Wei Jie 33,626 on at
    RE: How to get option set text from a pre image for plugins in MSCRM?

    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

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans