Solved

inspecting the create date of the last note in a conversation.

  • 18 March 2024
  • 3 replies
  • 31 views

Badge +1

How would I get the create date of the last note added to a conversation in a workflow?

 

I can get the note collection from the note by conversation.

But without iterating through all the notes to find the youngest one is there a way to just fetch the array length?

assuming step 2 is the get notes by conversation getting the most recent created note would formulated how?

/#steps.2.body.data.//lastentryindex//.attributes.createdAt

icon

Best answer by nick.johnson 19 March 2024, 19:03

View original

3 replies

Hi Anthony!


You can pull that data by making an API call to the notes endpoint for the conversation. The “data” object in the API response will contain an array of all of the notes on the conversation starting with the oldest note, so the last object in the array will be the most recent note.

 

No need to iterate through all of the objects in the array - you can use “.length” on the array to get the array length, then the index of the newest note object will be the length minus 1.


Once you’ve got the object of the newest note, attributes.createdAt will be the date/time that the note was created.

I hope that helps, but if you have any other questions, please feel free to reach out to support@kustomer.com anytime!

Badge +1

In a step 2 I call a fetch notes by conversation.

 

With data resembling this:

{
  "response": {
    "statusCode": 200,
    "body": {
      "meta": {
        "pageSize": 100,
        "page": 1
      },
      "links": {
        "self": "...",
        "first": "...",
        "prev": null,
        "next": null
      },
      "data": [
        {
          "type": "note",
          "id": "...",
          "attributes": {
            "body": "This is the first note.",
            "createdAt": "2024-02-10T11:39:19.487Z",
            "updatedAt": "2024-02-10T11:39:19.496Z",
            "createdByTeams": []
          },
          "relationships": {
            "org": {
              "links": {
                "self": "..."
              },
              "data": {
                "type": "org",
                "id": "..."
              }
            },
            "customer": {
              "links": {
                "self": "..."
              },
              "data": {
                "type": "customer",
                "id": "..."
              }
            },
            "conversation": {
              "links": {
                "self": "..."
              },
              "data": {
                "type": "conversation",
                "id": "..."
              }
            },
            "userMentions": {
              "data": [
                {
                  "type": "user",
                  "id": "..."
                }
              ]
            }
          },
          "links": {
            "self": "."
          }
        },

 

I tried this in a condition:

/#steps.2.body.data.{{{steps.2.body.data.length-1}}}.attributes.createdAt   ← I was unsure as to the syntax here as there is no documentation for it and square brackets like in javascript don’t seem to work either.

 

but it didn’t return any result so I tried to create a new note with just the createdAt date from the first note:
{{{steps.2.body.data.0.attributes.createdAt}}}
and got an empty string.

 

Any ideas?

Hi Anthony!

 

Sorry to re-route things here, but I found a much simpler way to approach this. My original thought would have involved a few extra action steps and is more complicated than necessary. This approach doesn’t involve any extra action steps. Use this code to pull the date/time of the most recent note in the conversation after the fetch notes by conversation step:

 

{{#each steps.2.response.body.data}}{{#if @last}}{{this.attributes.createdAt}}{{/if}}{{/each}}

 

You can insert that code wherever you need to use the date/time of the most recent note. Important to remember though - that time will be in UTC, not in your local timezone.

Reply