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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Suggested Answer

How to get optionset value in Fetchxml Alias entity c#

(0) ShareShare
ReportReport
Posted on by 242

How to get optionset value in Fetchxml Alias entity in C#? i am using two entity in fetchxml i want to get second entity optionset value or text using c#

I have the same question (0)
  • Suggested answer
    Naveen Ganeshe Profile Picture
    3,397 User Group Leader on at

    Hi Rocky,

    You can use the below code to get aliased option set value:

    string query = @"
                    
                    
                    
                    
                      
                    
                    
                      
                    
                  ";
    
    FetchExpression fetchExpression = new FetchExpression(query);
    
    
    EntityCollection entCollection = _service.RetrieveMultiple(fetchExpression);
    
    
    if (entCollection.Entities[0].Contains("statusoption"))
          int statusValue = ((OptionSetValue)entCollection.Entities[0].GetAttributeValue("statusoption").Value).Value;

  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at

    This will also works for you -

                        EntityCollection _EntityCollection1 = new EntityCollection();
                        _EntityCollection1 = Service.RetrieveMultiple(new FetchExpression(fethXML));
                        if (_EntityCollection1.Entities.Count > 0)
                        {
                            foreach (Entity ca in _EntityCollection1.Entities)
                            {
                                Int32 optionsetVal;
                                //Make sure you write here fetchxml link entity alias name.field name
                                AliasedValue categoryAliasVal = ca.GetAttributeValue("ab.accountcategorycode");
                                if (categoryAliasVal != null)
                                {
                                    optionsetVal = ((categoryAliasVal.Value) as OptionSetValue).Value;
                                }
                            }
    
                        }

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
ManoVerse Profile Picture

ManoVerse 94 Super User 2026 Season 1

#2
Muhammad Shahzad Shafique Profile Picture

Muhammad Shahzad Sh... 69 Most Valuable Professional

#3
11manish Profile Picture

11manish 68

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans