0

I wish to get most recent collection from my json array based on created date in logic app variable or using dot liquid transformation.

{
  "content": [
    {
      "properties": {
        "id": "957777746054",
        "owner": "jFinder",
        "created": "2021-03-30T04:12:18+0000",
        "updated": "2021-03-30T04:12:18+0000",
        "revision": "1"
      }
    },
    {
      "properties": {
        "id": "957777725902",
        "owner": "jFinder",
        "created": "2021-03-29T16:50:21+0000",
        "updated": "2021-03-29T16:50:21+0000",
        "revision": "1"
      }
    }
  ]
}

My idea was to sort this by "created" and then iterate over to pick first/last. But sort logic is not working. Can you help?

My liquid map start with

{% assign current = content.properties | Sort: "created" %}

{%- for item in current %}{"id" : "{{ current.id }}",do whatever} {%- endfor -%}

this always returns nill. I replaced created with id to see if that works but also didnt help

Skin
  • 9,085
  • 2
  • 13
  • 29

2 Answers2

0

My answer is half baked and this is untested, but I think you have your liquid a little confused. I think it should look like this ...

{% assign current = content | Sort: "properties.created" %}

{%- for item in current %}{"id" : "{{ current.properties.id }}",do whatever} {%- endfor -%}

Your array is contained within the content property which means you should be looping over that and then referencing lower level, sub properties through the property property.

Now, if that doesn't work, my suggestion would be to look at using the Advanced Data Operations connector. There's an operation there called Sort Object Array ...

Sort Object Array

... and it takes in an array of complex objects and will sort it based on your instructions.

Documentation can be found here ... https://www.statesolutions.com.au/sort-object-array/

So in relation to your requirement, this flow demonstrates the usage ...

Flow

I loaded your data in to a variable called Data and then in the next step, I refer to the underlying Content array and then sort it by properties.created in an ascending order.

It's a little bit hard to show in a single screenshot but you can see it's ordered it as instructed to ...

Result

Skin
  • 9,085
  • 2
  • 13
  • 29
0

Alternatively, I could get desired results following the below process.

Here is the sample json I used adding some more data to yours.

{
  "content": [
    {
      "properties": {
        "created": "2021-03-30T04:12:18+0000",
        "id": "957777746054",
        "owner": "jFinder",
        "revision": "1",
        "updated": "2021-03-30T04:12:18+0000"
      }
    },
    {
      "properties": {
        "created": "2021-03-29T16:50:21+0000",
        "id": "957777725902",
        "owner": "jFinder",
        "revision": "1",
        "updated": "2021-03-29T16:50:21+0000"
      }
    },
    {
      "properties": {
        "created": "2021-04-30T04:12:18+0000",
        "id": "957777746054",
        "owner": "jFinder",
        "revision": "1",
        "updated": "2021-03-30T04:12:18+0000"
      }
    },
    {
      "properties": {
        "created": "2021-01-30T04:12:18+0000",
        "id": "957777746054",
        "owner": "jFinder",
        "revision": "1",
        "updated": "2021-03-30T04:12:18+0000"
      }
    }
  ]
}

Flow in my logic apps

enter image description here

enter image description here

I am trying to compare 2 dates from the json and updated Ticks and FinalObject variables with the latest date's ticks and the current item.

Results:

enter image description here

SwethaKandikonda
  • 7,513
  • 2
  • 4
  • 18