Hi all, I have a table, and I want to send the rows of data as a JSON array, to a PDF generator so that a PDF report can recreate the table as it appears on my bubble page.
I know my JSON is not creating separate items inside the object, and instead is sending a comma separated list to the first row. How can I rewrite the JSON so that each item lands in it’s own row?
thanks again @cmarchan. I still don’t know what you mean. I have dynamic values in my original post. I don’t understand your reference to searching and including arbitrary text.
“line_items1” is the object that will have a dynamic number of entries (each including date,service, total).
Also thanks @Baloshi69
Hi all, does anyone know how to get bubble to insert all the objects “line_items1” from the table data, into JSON, so I can pass that array to the PDF generator API, thus recreating the table in PDF?
the present way I show above just creates 1 object containing lists of each dataset. Thanks!
If you have a static number of rows, follow @cmarchan advice an prepare an expression for EACH line, something like this:
“line_items”: [
{“date”: “Table GetClientPurchases Purchase’s List of GetClientPurchases Purchases: item # 1 Sale SaleDate: formatted as November 8, 2024”, “service”: “Table GetClientPurchases Purchase’s List of GetClientPurchases Purchases: item #1 Description”, “total”: “Table GetClientPurchases Purchase’s List of GetClientPurchases Purchases: item #1 AmountPaid: formatted as $1,028.58”},
// Additional items…
]
But if you have a dynamic number of lines I would recommend create a backend workflow to create a loop and for each line of the table you insert an element in a element.
I have looked into running a backend workflow and there doesn’t seem to be a way to do this. My table will have a dynamic number of rows. I need a way to generate and send the table row info as an JSON object. I would think many people would want this functionality.
@matt.braga thank you so much for taking the time to create this workflow and video! It is a very interesting approach. For me one of the hurdles I have is that I’m pulling the history of purchases from an API datasource (as opposed to having list of things in the database). I don’t know if this makes it more complicated or not but I don’t necessarily need to start with the data in a table. what I am doing is calling the API for a customer’s purchase history, and returning the date, type, and amount, then assembling that data in json so the PDF generator can accept the objects and place them correctly.
You need to start by breaking up “TableGetClientPurchases” by using: each item is not empty" format as text, then you can apply your JSON Structure PER item. Right now your structure is sending ALL items in a single row.
Huge thanks to @matt.braga and @cmarchan for the help here. I have found a solution. As @matt.braga suggested, I created a thing to receive the JSON that I created with a recursive workflow. My steps below:
create a datatype “history” with a text field “JSON” as a list.
on the page with my Table, I have a button to start the workflow, the first step is to search for a “history” record (with any contraints you need), then clear out the “JSON” field.
Next step is to schedule a backend workflow: the list to run on is the table, and the parameters are the names of JSON records I want in my array… I add 2 seconds in between recursive loops and schedule it to start 15 seconds after the first step (so I make sure clearing the list was completed first)
The backend workflow makes changes to the "history record, but setting “This JSON” to arbitrary text that contains the JSON string I need… The result is the “JSON” field having a comma separated list of JSON as a string.
The next step is anothe backend workflow that sends the information to the PDF Generator. It works great. Screenshots below.