Creating a table in Google Doc from an Array of information

Anyone got a tutorial on how to take an array of items and turn them into or add them to a table in a google doc? Like five rows, 4 columns. I’m kind of stuck…

What I have right now is a purchase order template inside a google doc. When someone places an order on my site certain fields are populated on that template. So far everything works great.

What I am missing is that the order may contain multiple products that were added to the cart and I need to take those items into a table in the template. For example one person may order 3 items and another may order 6 items. So I need to dynamically insert each line into the table on the template.

The table has a Product Name, Quantity, Price, and Subtotal.

Right now I send all of the items ordered into one cell and then manually fix the new purchase order before I finalize it.

Hi John,
I don’t have a complete tutorial, but have you tried using “Google Docs → Make an API call”? So, for example to create a table of five rows and four columns you would call POST /v1/documents/{{documentID}}:batchUpdate with a payload:

{
  "requests": [
    {
      "insertTable": {
        "rows": 5,
        "columns": 4,
        "location": {
          "segmentId": "",
          "index": 1
        }
      }
    }
  ]
}

This adds a new empty table to the documents body.

2 Likes

@zezutom Thanks for that idea, I’ll look into it. It may get me closer. I’ll update my post with a little more detail to try to better explain what I want to achieve.

1 Like

Reading your updated description, now it makes a perfect sense! I think you are close to have it solved. If I were you, I would add Google Docs → Make an API call as a follow-up action for Google Docs -> Create a Document from a Template. For each of the purchased items, you want to make an InsertTableRowRequest in the same fashion as I shared in my previous comment (the payload would be of course different).

3 Likes

If you know HTML, you can place a set variable between your iterator and text aggregator and set it up so that it does the HTML for each row.

The only catch is you won’t be able to use the Create a Document from a Template, you’ll have to use the Create the Document module instead.

2 Likes

Hey @zezutom have you been successful in getting the Make and Api call work with a Google doc module? I’m stuck on this… I was trying to test out your idea but have had no luck today.

hi @johnematias ,
I have indeed. See the attached blueprint, hope you find it useful.
blueprint.json (8.9 KB)

In a nutshell, it picks the first doc in a root folder on my (test) google drive, stores the document id and makes an api call appending an empty table using the document id.

4 Likes

@zezutom You are awesome! Thanks so much for sharing that. I was able to get the blueprint to work in a test the way you have it set up in that example. And I figured out my error by looking at how you had the make an api module set up.

I’ll be working to see if I can configure the insert table row request today. Fingers crossed! :slight_smile:

2 Likes

You are welcome, glad I could help.

2 Likes

Hi there,

first post.
I hope this community becomes the No.1 reference for integromat/make (once it will show up in google search results).

I had the same issue and came across several approaches:

In implementing the 4th approach, there were still a few pitfalls/learnings down the road, which I want to share:

  1. iterate through the reserve(body.content) array
  2. filter if “table” exists
  3. reserve bundle order by setting a variable to: “total number of bundles” +1-“bundle order position”
  4. (optional) get a reference from the first cell of a table: {{9.body.content[30.reversed order].table.tableRows[1].tableCells[1].content[1].paragraph.elements[1].textRun.content}}
  5. search rows in google sheets whose content you want to insert in google docs
  6. aggregate the desired content and the tables’ start index, end index and reversed order to an array
  7. iterate array
  8. make a POST request to this URL: /v1/documents/{{9.documentId}}:batchUpdate with the following body:
    {
    requests: [
    {
    insertTableRow: {
    tableCellLocation: {
    tableStartLocation: {
    index: {{9.body.content[43.reversed order].startIndex}}
    },
    rowIndex: 1,
    columnIndex: 0
    },
    insertBelow: false
    }
    },
    {
    insertText: {
    location: {
    index: {{(9.body.content[43.reversed order].endIndex - 2)}}
    },
    text: “XY”
    }
    }
    ]
    }
3 Likes

Thanks @Gregory the reverse order is a smart move! Could you share the blueprint of your scenario? I’m struggling to rebuild it.

I’m still stuck how to insert content via the API. @johnematias any advice or blueprints to look would be appreciated

Hi @johnematias , Can you share your scenario please? i tried to do that but i cant. thanks for the supporting @zezutom but i dont understand so much sorry.

Hey @Zbulo and @Antonio.Esquer - I didn’t end up using that technique for my situation. It turned out to just be too complicated and not worth the effort for me specifically. I got what I needed about 90% automated and the last bit isn’t much so I stopped there.

If you’re able to create a template in a Doc and insert your text into fields it makes it really easy to se things up. But if you need to build it out programmatically then I’d definitely recommend looking at what @Gregory posted above. Wish you luck on this one!

1 Like

Thank you @johnematias , I solve this whit this article Google Docs API call to insert content from one Google Doc into another - #15 by D-EFFCON

I hope support you.

2 Likes

can you please elaborate as it seems easy

Hello @Gregory , May I contact u in order to help me to do this scenario please?

I want to do like this Make example, BUT not only create one row of the table I want to do it a dynamic table data, not only one row

https://www.make.com/en/templates/3244-create-a-quote-with-google-docs-for-each-new-row-in-google-sheets

It is possibe to do it on microsoft word like this
https://www.make.com/en/help/app/microsoft-word-templates?_ga=2.149167155.48735797.1693790036-1272825930.1692310343&_gac=1.156315081.1692310343.CjwKCAjwivemBhBhEiwAJxNWNyrZ6L8nTITcKsiTT1je_Zp2fGYFsco6_dl01Mxw6BS_-7YwZRwgNBoCVKcQAvD_BwE&_gl=1*1k4la28*_ga*MTI3MjgyNTkzMC4xNjkyMzEwMzQz*_ga_MY0CJTCDSF*MTY5NDA1NzE0MS4zMC4xLjE2OTQwNTg4ODEuMTQuMC4w

but ur solution sounds the better

Thanks

1 Like

Hello, @Gregory could u send me the google docs and sheets example that you used? also the JSON of your scenario. It will be really helpful :smiley: :smiley: :smiley: I tried to created ur scenario but just can’t