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:
@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.
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).
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.
@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!
reserve bundle order by setting a variable to: “total number of bundles” +1-“bundle order position”
(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}}
search rows in google sheets whose content you want to insert in google docs
aggregate the desired content and the tables’ start index, end index and reversed order to an array
iterate array
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”
}
}
]
}
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!
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 I tried to created ur scenario but just can’t