Getting this error; Please use a numerically indexed array

Options

I've created a 'for each' loop to change the format of my timestamp. However, when I run it, I receive the error message 'Please use a numerically indexed array.'

Does anyone know what I'm doing wrong?


Here you can see what is happening:

https://www.loom.com/share/3eedaf9c07b045cea31aca66ca7dcb8f?sid=822c9b89-7dc0-4895-9c82-e136b2c6197c

Best Answer

Answers

  • Pawel Magdanski
    Pawel Magdanski Member ✭✭✭
    Options

    You are using get record for expeditions, it returns one object not an array, So probably the first loop is a proble here.

  • qb
    qb Member
    Options

    Thanks! Do you know what I need to change in the first loop to solve the problem?

  • frederic
    Options

    Hello,
    Instead of using a "get record" request you should use a "query all records" function.

    With the "get record expedition", you'll get only one expedition inside the variable, with the "query all records", you'll get an array of expeditions.

    The loop needs an array to iterate.

  • qb
    qb Member
    Options

    Thank you! I'm already using a 'query all records' request, but for my application to function properly, I also need a 'get record' request to retrieve a specific expedition.

    My goal is to convert the 'date' timestamp, which is in an add-on, to a more readable format. Is it possible to achieve this with my current 'get records' setup?

  • frederic
    frederic Member
    edited September 2023
    Options

    "My goal is to convert the 'date' timestamp, which is in an add-on, to a more readable format. Is it possible to achieve this with my current 'get records' setup?"

    Xano has a filter to convert timestamp to a more readable format:

    I don't know if there is a way to format that data "on the fly" within the addon inside the "get record setup".

    But depending on your datas volumetry and possible performance issue of doing it like that, you should have probably originally store that data in another column of your table with the correct format? So that you can have it directly in your addon without any transformation while retrieved.

    i hope that it can helps

  • Pawel Magdanski
    Pawel Magdanski Member ✭✭✭
    Options

    In terms of first loop, just delete it and in second loop use expeditions.sessions.id. And I don;t think you need the last loop either. Your sessions addon is as "self". The best way to build is to run&debug your function stack on every step of the way to see what you are getting after this step and if this is what you need.

    Regarding changing the date format. If that is just a display thing for the users, then it might be best to just adjust the format on the front-end side.