Extending CSV export to an addon (Split data to columns)

Options

Hi @Michael Udinski :),

I went through your video (

and achieved everything, the only issue I have now is when adding data from an addon, the columns come all together as one, how can we also split the addon data as separated columns? Thank you very much.

Tagged:

Answers

  • Michael Udinski
    Michael Udinski Administrator

    ADMIN

    Options

    Hey @JJ without seeing your response structure, I'm assuming your Addon results in a nested object. CSVs don't really work with nested objects in the flexible way that JSON does. CSVs like everything on one level. If your Addon is a single object and not an array, there's a quick trick that you can do. Return the Addon without a name, otherwise known as As Self. When configuring the Addon from the Query All Records, delete any string where it says “As _____”. This will roll all the fields of the Addon into the parent query. If any of the Addon fields have the same names as any in the parent query, the ones from the Addon will disappear to avoid conflict.

  • JJ
    JJ Member
    Options

    Hi @Michael Udinski ,

    Really cool, I already see the data separated, so really good progress, the only challenge now is that the headers are not available in the CSV.

    My structure is simple, I am just pulling info from text fields as you can see in the screenshoot below:

    Thank you very much

  • JJ
    JJ Member
    Options

    Hi @Michael Udinski ,

    I have been around the bushes and so far didn't get lucky, I tried with EVAL, Joins, but seems only addon brings info, but no column headers still, is this a limitation by bringing in the data as an addon? Is there a way of creating the columns manually and doing a sort of append data? Thank you very much.

  • Michael Udinski
    Michael Udinski Administrator

    ADMIN

    edited March 2023
    Options

    @JJ can you provide a loom video or detailed screenshots of your function stack?

  • JJ
    JJ Member
    edited March 2023
    Options

    Thanks @Michael Udinski , I will try this way (Not to share the api endpoint).

    I have the Main Table with the following schema

    Account Table

    {id: integer created_at: timestamp user_idname: text Title: text formatted_address: text Address: text}

    Account Business Hours table (name: business_hours)

    {id: integer created_at: timestamp Open_0: text Close_0: text Open_1: text Close_1: text Open_2: text Close_2: text Open_3: text Close_3: text Open_4: text Close_4: text Open_5: text Close_5: text Open_6: text Close_6: text iwp_id: integer}

    I connect the data from Account Business hours table via the addon to the Account Table through id = iwp_id (addon as "_business_hours)

    Stack is basically same as the video

    And how the addon pulls the data from the business hours table, as suggested I left the "AS" empty to do the proper split.

    Thank you very much.

  • Michael Udinski
    Michael Udinski Administrator

    ADMIN

    Options

    If you do a stop&debug after Get Keys and return the var:columns what is the result?

  • JJ
    JJ Member
    edited March 2023
    Options

    I only get the columns from the original table (Account) that I have in the "Query All Records From…" output

    [id,created_at,user_id,name,title,formatted_address,address]

    In the Run&Debug breakdown, you can see that in the Model Get keys Model.0 output, only columns available in the main table are set as output JSON array.

    The curious thing is that the addon data (Table business hours) is not visible on that output of the model.0. the data is only available when exporting the actual CSV.

  • JJ
    JJ Member
    edited March 2023
    Options

    I think I am on to something.

    When I pulled all the values for the main table, and if it does not find a value for the record (I would assume first), so the column names come empty.

    This time I pulled one unique record that I knew for sure that the record had addon data, and the columns appear:

    So it seems it is not pulling the column headers if I would assume the first record is empty, so cannot find data in the addon table for the first record?

    Seems a bit like Airtable API behaviour, you cannot have the proper schema into an external database if the table does not have data in those columns, but here seems more complex as I only had one record, with data, so should be able to bring the schema.