I use this JSON structure in Make to handle data from a web hook, clean it with GPT4o as a JSON output, and insert the items in a Google Docs template. However the item amount can vary. How can I account for this? Because if I had for example 10 items once I would need 10 placeholders in the Google Doc. But if it’s less than that I don’t want there to be empty placeholders. Is there a way to keep the placeholders more dynamic? For example only add a table row for every item?
The only way is to build the entire document using HTML (which includes tables and dynamic table rows), then use the “Create a Document” (no template).
If there is no data you can use {{emptystring}}, but that will only clear the placeholder and not the border around the cell which contains it.
I’ve done this several different ways and how Sam described it has by far been the easiest.
Here are the others I’ve tried…
Method 1
Use Make an API Call to download the contents of the final document, find the table, remove the rows you didn’t use.
The downside to this, this won’t help if you’ve got more items than your template has placeholders for.
Method 2
Much more difficult to implement, but can handle any number of items you have.
Leave your template just with a header and the blank first row.
When you build your document, you will end up with a table contains 2 rows:
The header row with Item and the value for {{Project Name}}.
The first row of data which will be blank.
Then, download the contents of the document, find the table’s index, and insert a row (this will push the original data row down leaving you with a header row and two blank rows.
You can use this same index to insert as many rows as you need.
After each row insert, you can place data in the last row of the table, so the data needs to be added to the table in reverse.
By the time all is done you’ll need up with a table containing your data and a blank row between the header and your first row of data.
Using that same index number, delete that blank row.
You need this blank row so that inserted rows inherit the formatting of the data row instead of the header row.
I will try first to recreate the Google Doc in HTML. Gonna try GPT4o for that because I can’t code myself…
I googled the {{emptystring}} thing but it doesn’t seem to exist in Google Docs.
Method 1 and 2 both make sense to me, but I don’t think you can search/add/remove rows in a Google Doc because it’s basically just formatting. Would have to switch to Sheets for this.
Again: Thanks a lot and I will try the HTML solution!
If you don’t get the results you expect, you can download a Google doc as HTML then just clean up that code. There you can find the table and replace the row with all of your rows, which you could build using an iterator and text aggregator.
{{emptystring}} is a special code in Make. When written like that it translates to blank text. When used in a Google Docs module where you need to replace a placeholder in the document with no text. Looks like this:
In Google Docs, everything has an index to represent its content, formatting, and place in the document.
When you add things at the bottom, the index number of each object (table, block of text, image, etc…) increases.
When you insert things in the middle then the index of everything you added takes the place of objects that were there then the index of everything that was “pushed” down gets recalculated.
In the case of a table within a document, once you locate the index of row 1, you can insert a row as many times as you want and the index never changes; you just need to add rows in reverse since they’re all getting pushed down every time a row is inserted.
At the end you can use the same index number to delete that row.