Announcements
No record found.
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#
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;
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.
Congratulations to our 2026 Super Stars!
We are thrilled to have these Champions in our Community!
These are the community rock stars!
Stay up to date on forum activity by subscribing.
Muhammad Shahzad Sh... 69 Most Valuable Professional
ManoVerse 62 Super User 2026 Season 1
11manish 43