RE: FetchXML aggregation for two option fields
Hi,
Thank you for your query.
As you can see by the error it is not possible Aggregate on bit (2 optionset) fields.
However you can use DISTINCT operator.
Here is the example FetchXML:
Please note, distinct="true" added in the FechXML and it should return 2 records (at MAX).
An alternated approach to your scenario is:
- Retrieve Records where field1 is true.
- Set Top to 1, so we get first record where field1 is true.
- If the result count is greater than 0, you have your answer.
For instance here is the example FetchXML:
If there are any results returned from above query, we will get to know if there are any records where field1 is set to true.
Here is example C# code for your reference:
string qry = @"
";
FetchExpression fetchExpression = new FetchExpression(qry);
var results = svc.RetrieveMultiple(fetchExpression);
if (results.Entities.Count==1)
{
// There are records where field1=true
return true;
}
Let me know if you need further clarification.
Best,
Wahaj
(if this helps, please mark it as verified)