Skip to main content

Notifications

Microsoft Dynamics CRM forum
Answered

Filtering expand or relationship query on a date field results in error "UserId is empty guid!"

Posted on by 20

Screenshot-2020_2D00_11_2D00_25-102806.png

I want to construct a query such as the following

/api/data/v9.0/EntityA(0928aeff-60d2-ea11-a2da-0050568beee8)/ManyRelationship?$filter=modifiedon%20ne%20null%20and%20modifiedon%20gt%202020-11-25T09:05:59.9361388-06:00

or

/api/data/v9.0/EntityA(0928aeff-60d2-ea11-a2da-0050568beee8)?$expand=ManyRelationship($filter=modifiedon%20ne%20null%20and%20modifiedon%20gt%202020-11-25T08:54:15.5749064-06:00)

however, both queries return a 404 with the error 

{"error":{"code":"0x80040217","message":"UserId is empty guid! ","innererror":{"message":"UserId is empty guid! ","type":"Microsoft.Crm.BusinessEntities.CrmObjectNotFoundException","stacktrace":" at Microsoft.Crm.Caching.UserDataCacheLoader.<>c__DisplayClass2_0.<LoadCacheData>b__0()\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 Microsoft.Crm.Caching.ObjectModelCacheLoader`2.LoadCacheDataInternal(TKey key, Object existingDataContainer, IOrganizationContext context)\r\n at Microsoft.Crm.Caching.ObjectModelCacheLoader`2.LoadCacheData(TKey key, IOrganizationContext context)\r\n at Microsoft.Crm.Caching.CrmMultiOrgCacheBase`2.CreateEntry(TKey key, IOrganizationContext context)\r\n at Microsoft.Crm.Caching.CrmMultiOrgCacheBase`2.<>c__DisplayClass19_0.<LookupEntry>b__2()\r\n at Microsoft.PowerApps.CoreFramework.ActivityLoggerExtensions.Execute(ILogger logger, EventId eventId, ActivityType activityType, Action action)\r\n at Microsoft.Xrm.Telemetry.XrmTelemetryExtensions.Execute(ILogger logger, XrmTelemetryActivityType activityType, Action action)\r\n at Microsoft.Crm.Caching.CrmMultiOrgCacheBase`2.LookupEntry(TKey key, IOrganizationContext context)\r\n at Microsoft.Crm.BusinessEntities.CrmDateTimeBuilderBase.ConvertUtcTimeToUserTime(DateTime utcTime, IUserAndOrganizationContext userAndOrganizationContext)\r\n at Microsoft.Crm.BusinessEntities.DynamicCrmDateTimeBuilder.ConvertToCrmDateTime(DateTime dateTime, IUserAndOrganizationContext userAndOrganizationContext, DateTimeToCrmDateTimeConversionStrategy strategy)\r\n at Microsoft.Crm.Query.DateTimeConditionParser.GetCrmDateTime(AttributeMetadata attribute, Object value, IUserAndOrganizationContext userAndOrganizationContext)\r\n at Microsoft.Crm.Query.ConditionExpression..ctor(AttributeMetadata attribute, ConditionOperator conditionOperator, Array values, Boolean isCustom, IUserAndOrganizationContext userAndOrganizationContext, DynamicMetadataCache cache)\r\n at Microsoft.Crm.Extensibility.OData.DataQueryOptionsConverter.GetConditionExpression(Object leftVal, BinaryOperatorNode node, Object rightVal, Boolean negateOperator)\r\n at Microsoft.Crm.Extensibility.OData.DataQueryOptionsConverter.BindBinaryOperatorNode(BinaryOperatorNode binaryOperatorNode, FilterExpression parentFilter, Boolean negateOperator)\r\n at Microsoft.Crm.Extensibility.OData.QueryOptionsConverterBase`4.Bind(QueryNode node, TFilterExpression parentFilter, Boolean negateOperator, XrmMetadataEntityMetadata metadata)\r\n at Microsoft.Crm.Extensibility.OData.DataQueryOptionsConverter.BindBinaryOperatorNode(BinaryOperatorNode binaryOperatorNode, FilterExpression parentFilter, Boolean negateOperator)\r\n at Microsoft.Crm.Extensibility.OData.QueryOptionsConverterBase`4.Bind(QueryNode node, TFilterExpression parentFilter, Boolean negateOperator, XrmMetadataEntityMetadata metadata)\r\n at Microsoft.Crm.Extensibility.OData.QueryOptionsConverterBase`4.BindFilterClause(FilterClause filterClause, XrmMetadataEntityMetadata metadata, Object[] args)\r\n at Microsoft.Crm.Extensibility.OData.DataQueryOptionsConverter.SetFilterExpression(EntityExpression qe, FilterQueryOption filterQueryOption, XrmMetadataEntityMetadata metadata)\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.DataQueryOptionsConverter.GetRelatedEntityQuery(ODataQueryOptions navigationEntityQueryOptions, String edmEntityName, String navigationProperty, String navigationEntityName, Boolean onlyRef)\r\n at Microsoft.Crm.Extensibility.OData.CrmODataServiceDataProvider.RetrieveEdmEntityNavigation(CrmODataExecutionContext context, String edmEntityName, String entityKeyValue, String navigationPropertyName, ODataQueryOptions queryOptions, Boolean onlyRef)\r\n at Microsoft.Crm.Extensibility.OData.EntityController.GetNavigationInternal(String entityName, String key, String navigation, String derivedNavigation, Boolean isMetadataEntity, CrmODataExecutionContext context, ODataQueryOptions queryOptions, CrmEdmEntityObjectCollection crmEdmEntityObject)\r\n at Microsoft.Crm.Extensibility.OData.EntityController.GetNavigationImplementation(String& entityName, String key, String navigation)\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()"}}}

I can use the following queries successfully so it seems to be a problem with the fact that I'm using a DateTime field in the filter.


/api/data/v9.0/EntityA(951ddc21-46ff-ea11-a2da-0050568beee8)/ManyRelationship?$filter=new_name%20eq%20%27test%27

/api/data/v9.0/EntityA(951ddc21-46ff-ea11-a2da-0050568beee8)?$expand=ManyRelationship($filter=new_name%20eq%20%27test%27)

Any guidance would be appreciated.

  • Majellin Profile Picture
    Majellin 20 on at
    RE: Filtering expand or relationship query on a date field results in error "UserId is empty guid!"

    Thank you for the information!

  • cloflyMao Profile Picture
    cloflyMao 25,196 on at
    RE: Filtering expand or relationship query on a date field results in error "UserId is empty guid!"

    Hi Majellin,

    Sorry for unclear clarification, "should" means that I'm not sure whether the On Premises has any other limitations compared to the Online version.

    As for their difference, I only found the following article, which introduced Web API Limitations that applies to Dynamics 365 On-Premises.

    https://docs.microsoft.com/en-us/previous-versions/dynamicscrm-2016/developers-guide/mt628816(v=crm.8)

    In addition, here is another old article about Web API data query sample, you could refer to it to build query in OP environment.

    https://docs.microsoft.com/en-us/previous-versions/dynamicscrm-2016/developers-guide/mt770367(v=crm.8)

    Regards,

    Clofly 

  • Majellin Profile Picture
    Majellin 20 on at
    RE: Filtering expand or relationship query on a date field results in error "UserId is empty guid!"

    Hi,

    Thanks for the response and recommendation.  

    Could you please clarify what you mean by "such query should not be supported in OP version?". Are you saying it's working as intended?  If so, do you happen to know why that is intended?

    I seem to keep running into various issues where functionality differs between the Online and On Premise versions and if this is intended or known to be the case it would be very helpful to know of there is some documentation somewhere which lists the various differences and potentially explains why they exist.

    Thanks again!

  • Verified answer
    cloflyMao Profile Picture
    cloflyMao 25,196 on at
    RE: Filtering expand or relationship query on a date field results in error "UserId is empty guid!"

    Hi Majellin,

    I tested it in my OP environment: it seems that if we specify a record and use date time field, then the error you mentioned will be thrown.

    [organization URL]/api/data/v9.0/EntityA(1a960cd0-ae2f-eb11-9c35-001dd8be05ce)?$select=name&$filter=createdon gt 2020-01-01
    

    pastedimage1606378316094v1.png

    While the query can be executed successfully in Online, so such query should not be supported in OP version.

    daa.JPG

    Instead, I would suggest converting the query to fetchXML.

       
          
          
             
             
                
             
          
          
             
          
       
    

    http://localhost/crm/api/data/v9.0/accounts?fetchXml=

    Regards,

    Clofly

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

Dynamics 365 Community Update – Sep 16th

Welcome to the next edition of the Community Platform Update. This is a weekly…

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Dynamics 365 Community Newsletter - September 2024

Check out the latest community news

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,522 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,441 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans