简体   繁体   中英

Filter Json by date in LogicApp

I have the following json which is built in a logic app, however the final result must be only the objects with a maximum date, that is, the final result must be only one record per object with the maximum date of that object.

[{
    "FechaUltimaCarga": "2020-09-14T14:00:07.8451571Z",
    "CollectionName": "PartOrder"
}, {
    "FechaUltimaCarga": "2020-09-14T21:00:07.8451571Z",
    "CollectionName": "PartOrder"
}, {
    "FechaUltimaCarga": "2020-09-14T14:00:07.8451571Z",
    "CollectionName": "PartOrderItem"
}, {
    "FechaUltimaCarga": "2020-09-13T17:00:07.8451571Z",
    "CollectionName": "Engineer"
}, {
    "FechaUltimaCarga": "2020-09-14T13:00:07.8451571Z",
    "CollectionName": "Engineer"
}, {
    "FechaUltimaCarga": "2020-09-13T03:00:07.8451571Z",
    "CollectionName": "Task"
}, {
    "FechaUltimaCarga": "2020-09-13T05:00:07.8451571Z",
    "CollectionName": "Task"
}, {
    "FechaUltimaCarga": "2020-09-13T06:00:07.8451571Z",
    "CollectionName": "Task"
}, {
    "FechaUltimaCarga": "2020-09-13T07:00:07.8451571Z",
    "CollectionName": "Task"
}, {
    "FechaUltimaCarga": "2020-09-13T10:00:07.8451571Z",
    "CollectionName": "Task"
}, {
    "FechaUltimaCarga": "2020-09-13T12:00:07.8451571Z",
    "CollectionName": "Task"
}, {
    "FechaUltimaCarga": "2020-09-13T13:00:07.8451571Z",
    "CollectionName": "Task"
}, {
    "FechaUltimaCarga": "2020-09-13T15:00:07.8451571Z",
    "CollectionName": "Task"
}, {
    "FechaUltimaCarga": "2020-09-13T16:00:07.8451571Z",
    "CollectionName": "Task"
}, {
    "FechaUltimaCarga": "2020-09-13T17:00:07.8451571Z",
    "CollectionName": "Task"
}, {
    "FechaUltimaCarga": "2020-09-13T18:00:07.8451571Z",
    "CollectionName": "Task"
}, {
    "FechaUltimaCarga": "2020-09-13T19:00:07.8451571Z",
    "CollectionName": "Task"
}, {
    "FechaUltimaCarga": "2020-09-13T20:00:07.8451571Z",
    "CollectionName": "Task"
}, {
    "FechaUltimaCarga": "2020-09-13T22:00:07.8451571Z",
    "CollectionName": "Task"
}, {
    "FechaUltimaCarga": "2020-09-14T03:00:07.8451571Z",
    "CollectionName": "Task"
}, {
    "FechaUltimaCarga": "2020-09-14T04:00:07.8451571Z",
    "CollectionName": "Task"
}, {
    "FechaUltimaCarga": "2020-09-14T05:00:07.8451571Z",
    "CollectionName": "Task"
}, {
    "FechaUltimaCarga": "2020-09-14T06:00:07.8451571Z",
    "CollectionName": "Task"
}, {
    "FechaUltimaCarga": "2020-09-14T07:00:07.8451571Z",
    "CollectionName": "Task"
}, {
    "FechaUltimaCarga": "2020-09-14T09:00:07.8451571Z",
    "CollectionName": "Task"
}, {
    "FechaUltimaCarga": "2020-09-14T10:00:07.8451571Z",
    "CollectionName": "Task"
}, {
    "FechaUltimaCarga": "2020-09-14T12:00:07.8451571Z",
    "CollectionName": "Task"
}, {
    "FechaUltimaCarga": "2020-09-14T13:00:07.8451571Z",
    "CollectionName": "Task"
}, {
    "FechaUltimaCarga": "2020-09-14T14:00:07.8451571Z",
    "CollectionName": "Task"
}, {
    "FechaUltimaCarga": "2020-09-14T15:00:07.8451571Z",
    "CollectionName": "Task"
}, {
    "FechaUltimaCarga": "2020-09-14T19:00:07.8451571Z",
    "CollectionName": "Task"
}, {
    "FechaUltimaCarga": "2020-09-14T20:00:07.8451571Z",
    "CollectionName": "Task"
}, {
    "FechaUltimaCarga": "2020-09-14T21:00:07.8451571Z",
    "CollectionName": "Task"
}, {
    "FechaUltimaCarga": "2020-09-14T22:00:07.8451571Z",
    "CollectionName": "Task"
}, {
    "FechaUltimaCarga": "2020-09-14T23:00:07.8451571Z",
    "CollectionName": "Task"
}, {
    "CollectionName": "PartOrder",
    "FechaUltimaCarga": "2020-09-13T00:00:07.8451571Z"
}, {
    "CollectionName": "PartOrderItem",
    "FechaUltimaCarga": "2020-09-13T00:00:07.8451571Z"
}, {
    "CollectionName": "PartsInStock",
    "FechaUltimaCarga": "2020-09-13T00:00:07.8451571Z"
}, {
    "CollectionName": "Engineer",
    "FechaUltimaCarga": "2020-09-13T00:00:07.8451571Z"
}, {
    "CollectionName": "Task",
    "FechaUltimaCarga": "2020-09-13T00:00:07.8451571Z"
}

]

The expected result should be one record per object with the max date obtained in the initial json:

[{
    "CollectionName": "PartOrder",
    "FechaUltimaCarga": "2020-09-14T21:00:07.8451571Z"
}, {
    "CollectionName": "PartOrderItem",
    "FechaUltimaCarga": "2020-09-14T14:00:07.8451571Z"
}, {
    "CollectionName": "PartsInStock",
    "FechaUltimaCarga": "2020-09-13T00:00:07.8451571Z"
}, {
    "CollectionName": "Engineer",
    "FechaUltimaCarga": "2020-09-14T13:00:07.8451571Z"
}, {
    "CollectionName": "Task",
    "FechaUltimaCarga": "2020-09-14T23:00:07.8451571Z"
}

]

How can I get this result?

I appreciate your help

I designed a azure logic app workflow for you:

You can convert Json to an array, and then use the Filter array action to filter out the array items whose CollectionName is equal to PartOrder

在此处输入图片说明

Then you can use the Select action to fetch the value of FechaUltimaCarga , use the inline code to execute the js code to compare dates, and the result will return the maximum value of the dates.

在此处输入图片说明

Then you use for each to traverse your json array, and use the condition action within for each to add eligible items to the empty array created earlier.

在此处输入图片说明

You need to repeat the above operation, because you also need to filter the array items whose CollectionName is equal to PartOrderItem , PartsInStock ...

Finally, you can directly convert the resulting array into a string, which is the json value you want.

在此处输入图片说明

I did a test, but only filtered the array items whose CollectionName is equal to PartOrder , and the result is the expected value. You can complete the logic app workflow according to my logic.

在此处输入图片说明

Note

Implementation of inline code requires Integration accounts .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM