From 8c1dfa1a54d22c1fd5debcd8610ff4659cf1f5fd Mon Sep 17 00:00:00 2001 From: Olivier Marguillard Date: Fri, 22 Oct 2021 15:05:28 +0200 Subject: [PATCH] Fix paging issue with sysparm_display_value=true --- ServiceNow.Api/ServiceNowClient.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/ServiceNow.Api/ServiceNowClient.cs b/ServiceNow.Api/ServiceNowClient.cs index 08c4dab..4163831 100644 --- a/ServiceNow.Api/ServiceNowClient.cs +++ b/ServiceNow.Api/ServiceNowClient.cs @@ -312,7 +312,15 @@ internal async Task> GetAllByQueryInternalJObjectAsync( maxDateTimeRetrieved = response.Items.Max(jObject => { // Parse and enforce source as being UTC (Z) - return DateTimeOffset.Parse((jObject[_options.PagingFieldName]?.ToString() ?? string.Empty) + "Z"); + if (jObject[_options.PagingFieldName]?["value"] != null) + { + // This has a value and display_value subcomponent. We want to use the "value". + return DateTimeOffset.Parse((jObject[_options.PagingFieldName]?["value"]?.ToString() ?? string.Empty) + "Z"); + } + else + { + return DateTimeOffset.Parse((jObject[_options.PagingFieldName]?.ToString() ?? string.Empty) + "Z"); + } }); if (previousMaxDateTimeRetrieved == maxDateTimeRetrieved)