With the below results, I want to be able to get the latest run of the queue item.
The results are coming from
Results = arrJSON.Cast(Of JObject).Where(Function (x) x(“QueueItemId”).toString.Equals(strQueueID)).toList
where
arrJSON is coming from a deserialised JSON array of an Orchestrator HTTP request
Results is a Generic JObject List
@redanime94 ,
Did you try Results.Last ?
Or Results(Results.count-1)
If this doesn’t give latest data, then you can try Results(0) and check.
1 Like
Anil_G
(Anil Gorthi)
April 27, 2023, 3:50am
3
@redanime94
You can use .OrderByDescending(function(x) Cdate(x("DateKey").ToString)).FirstOrDefault
Change datekey to the actual key of the date field
Hope this helps
Cheers
it worked but the items are not sorted in descending / ascending order
Anil_G
(Anil Gorthi)
April 27, 2023, 4:13am
6
@redanime94
In the formula after the where clause add this …then the items would be sorted
arrJSON.Cast(Of JObject).Where(Function (x) x(“QueueItemId”).toString.Equals(strQueueID)).OrderByDescending(function(x) Cdate(x("DateKey").ToString)).FirstOrDefault
This gives the first item directly after sort
Cheers
Getting this error:
what type of variable should i use for the result please?
Anil_G
(Anil Gorthi)
April 27, 2023, 6:02am
8
@redanime94
I guess your results is of type list of jobject…please change it to jobject as you will get the latest directly…
Cheers
ppr
(Peter Preuss)
April 27, 2023, 7:48am
9
with firstOrDefault a single JObject or null is returned. So datatype of Results = JObject
As the Variable name is expressing a plural but statement returns a single element feel free also to check the variable name naming
system
(system)
Closed
May 4, 2023, 7:17pm
11
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.