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 :
Microsoft Dynamics CRM (Archived)

OData filter using EnumType values

(0) ShareShare
ReportReport
Posted on by

I have an Odata Query using a $filter with EnumType that is not working. The query is:

fpx-dev02.api.crm.dynamics.com/.../EntityDefinitions(LogicalName='opportunity')?$expand=Attributes($filter=AttributeType eq AttributeTypeCode'Virtual')

Dynamics CRM 365 returns message:

{"error":{"code":"0x0","message":"Unrecognized 'Edm.String' literal 'AttributeTypeCode'Virtual'' at '17' in 'AttributeType eq AttributeTypeCode'Virtual''.","innererror":{"message":"Unrecognized 'Edm.String' literal 'AttributeTypeCode'Virtual'' at '17' in 'AttributeType eq AttributeTypeCode'Virtual''.","type":"Microsoft.OData.ODataException","stacktrace":"   at Microsoft.OData.UriParser.UriQueryExpressionParser.ParseTypedLiteral(ExpressionLexer lexer, IEdmTypeReference targetTypeReference, String targetTypeName)\r\n   at Microsoft.OData.UriParser.UriQueryExpressionParser.TryParseLiteral(ExpressionLexer lexer)\r\n   at Microsoft.OData.UriParser.UriQueryExpressionParser.ParsePrimaryStart()\r\n   at Microsoft.OData.UriParser.UriQueryExpressionParser.ParsePrimary()\r\n   at Microsoft.OData.UriParser.UriQueryExpressionParser.ParseUnary()\r\n   at Microsoft.OData.UriParser.UriQueryExpressionParser.ParseMultiplicative()\r\n   at Microsoft.OData.UriParser.UriQueryExpressionParser.ParseAdditive()\r\n   at Microsoft.OData.UriParser.UriQueryExpressionParser.ParseComparison()\r\n   at Microsoft.OData.UriParser.UriQueryExpressionParser.ParseLogicalAnd()\r\n   at Microsoft.OData.UriParser.UriQueryExpressionParser.ParseLogicalOr()\r\n   at Microsoft.OData.UriParser.UriQueryExpressionParser.ParseExpression()\r\n   at Microsoft.OData.UriParser.UriQueryExpressionParser.ParseExpressionText(String expressionText)\r\n   at Microsoft.OData.UriParser.ExpandOptionParser.BuildExpandTermToken(PathSegmentToken pathToken, String optionsText)\r\n   at Microsoft.OData.UriParser.SelectExpandParser.ParseSingleExpandTerm()\r\n   at Microsoft.OData.UriParser.SelectExpandParser.ParseCommaSeperatedExpandList(Func`2 ctor, Func`1 termParsingFunc)\r\n   at Microsoft.OData.UriParser.SelectExpandSyntacticParser.Parse(String selectClause, String expandClause, IEdmStructuredType parentEntityType, ODataUriParserConfiguration configuration, ExpandToken& expandTree, SelectToken& selectTree)\r\n   at Microsoft.OData.UriParser.ODataQueryOptionParser.ParseSelectAndExpandImplementation(String select, String expand, ODataUriParserConfiguration configuration, ODataPathInfo odataPathInfo)\r\n   at Microsoft.OData.UriParser.ODataQueryOptionParser.ParseSelectAndExpand()\r\n   at Microsoft.Crm.Extensibility.OData.MetadataQueryOptionsConverter.BindSelectExpand(EntityQueryExpression qe, SelectExpandQueryOption selectExpandQueryOption)\r\n   at Microsoft.Crm.Extensibility.OData.QueryOptionsConverterBase`4.GetQueryExpression(ODataQueryOptions queryOptions, String edmEntityName, CrmODataExecutionContext context, XrmMetadataEntityMetadata metadata)\r\n   at Microsoft.Crm.Extensibility.OData.MetadataQueryOptionsConverter.GetEntityQueryExpression(ODataQueryOptions queryOptions, String edmEntityName, CrmODataExecutionContext context, String key)\r\n   at Microsoft.Crm.Extensibility.OData.CrmODataMetadataServiceDataProvider.RetrieveEdmEntity(CrmODataExecutionContext context, String entityName, String key, ODataQueryOptions queryOptions)\r\n   at Microsoft.Crm.Extensibility.OData.EntityController.GetEntityImplementation(String& entityName, String key)\r\n   at Microsoft.PowerApps.CoreFramework.ActivityLoggerExtensions.Execute[TResult](ILogger logger, EventId eventId, ActivityType activityType, Func`1 func)\r\n   at Microsoft.Xrm.Telemetry.XrmTelemetryExtensions.Execute[TResult](ILogger logger, XrmTelemetryActivityType activityType, Func`1 func)\r\n   at lambda_method(Closure , Object , Object[] )\r\n   at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass10.<GetExecutor>b__9(Object instance, Object[] methodParameters)\r\n   at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancellationToken)\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Controllers.ApiControllerActionInvoker.<InvokeActionAsyncCore>d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__2.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__1.MoveNext()"}}}

The URL below with Namespace all fails:

fpx-dev02.api.crm.dynamics.com/.../EntityDefinitions(LogicalName='opportunity')?$expand=Attributes($filter=AttributeType eq mscrm.AttributeTypeCode'Virtual')

https://[mytenant].dynamics.com/api/data/v9.0/EntityDefinitions(LogicalName='opportunity')?$expand=Attributes,ManyToManyRelationships($select=SchemaName,Entity1LogicalName,Entity2LogicalName,Entity2AssociatedMenuConfiguration),ManyToOneRelationships($select=SchemaName,ReferencedEntity,ReferencedAttribute,ReferencingEntity,ReferencingAttribute,ReferencingEntityNavigationPropertyName,ReferencedEntityNavigationPropertyName)&$select=LogicalName,SchemaName,DisplayName,LogicalCollectionName

Used this as a reference: https://www.schaeflein.net/filter-using-enum-values-in-odata-v4/

How can this be done? 

*This post is locked for comments

I have the same question (0)
  • Community Member Profile Picture
    on at

    Found it

    fpx-dev02.api.crm.dynamics.com/.../EntityDefinitions(LogicalName='opportunity')?$expand=Attributes($filter=AttributeType eq Microsoft.Dynamics.CRM.AttributeTypeCode'Virtual')

    Do not use the Namespace alias.

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 > 🔒一 Microsoft Dynamics CRM (Archived)

#1
ScottDurow Profile Picture

ScottDurow 2

#2
GJones Profile Picture

GJones 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans