Using arrays in the pdfmonkey integration

Need help with sending an array of items to pdfmonkey using the integration. How should the data be presented. It seems to only accept a joined list but when I run it the data does not get entered into the pdf. Onlythe integers and text do and not the arrays.

At the moment I don’t think the PDF integration allows arrays. I believe they plan to introduce a “line items” thing at some point, since that is one of the best features in PDFMonkey in my opinion.

2 Likes

For the moment, I think the best thing you can do is to create the HTML part in advance in Glide, then pass that as a variable to your PDFMonkey generation flow.

1 Like

You would regenerate the entire HTML using a Template column? Or can I just recreate the Table portion of the HTML?
Also not sure ho to turn 2 array columns (Timecard Date and Timecard Pay) into the correct fields.
Ideas?

This part. How do you plan to show it in your PDF?

as a table. Here is the HTML currently…

<!DOCTYPE html>
<html>
<head>
	<title>Job PDF Template</title>
	<style>
		body {
			font-family: Arial, sans-serif;
			font-size: 12px;
		}

		h1 {
			font-size: 24px;
			margin-bottom: 10px;
		}

		table {
			border-collapse: collapse;
			width: 100%;
			margin-bottom: 20px;
		}

		th, td {
			border: 1px solid black;
			padding: 5px;
			text-align: center;
		}

		.total {
			font-weight: bold;
			text-align: left;
			margin-top: 20px;
		}
	</style>
</head>
<body>
	<h1>Job Name: {{jobName}}</h1>
	<p><strong>Job Description:</strong> {{jobDescription}}</p>
	<p><strong>Date:</strong> {{jobDate}}</p>

	<table>
			<tr>
				<th>Timecard Date</th>
				<th>Timecard Pay</th>
			</tr>
		
			<!-- Loop through the timecard arrays and create a row for each item -->
			{% for item in lineItems %}
				<tr>
				  <td>{{item.timecardDate}}</td>
				  <td>{{item.timecardPay}}</td>
				</tr>
		{% endfor %}
	</table>

	<p class="total">Total Pay: {{allTotal}}</p>
</body>
</html>

I believe this is the only part you need a loop?

{% for item in lineItems %}
				<tr>
				  <td>{{item.timecardDate}}</td>
				  <td>{{item.timecardPay}}</td>
				</tr>
		{% endfor %}

In Glide, you can have a relation of “timecards”, on the “timecards” table, create a template for each row like this:

<tr>
<td>{{item.timecardDate}}</td>
<td>{{item.timecardPay}}</td>
</tr>

And replace the timecardDate and timecardPay accordingly.

Back to the job table where I assume you would have the timecard relation, create a joined list column to join all the templates over the timecard relation, separate by a newline character.

4 Likes

That worked…Thank you.

1 Like

Great to hear it worked!

Have a new issue with a new template. Here is the HTML. Not sure where to put the line items for this.

{% for job_index in (0..jobs.size) %} {% assign job = jobs[job_index] %} {% assign names_for_job = names[job_index] %} {% assign hours_for_job = hours[job_index] %}

{{ job }}

{% for names_index in (0..names_for_job.size) %} {% endfor %}
Timecard Name Timecard Hours
{{ names_for_job[names_index] }} {{ hours_for_job[names_index] }}
Total {{ totals[job_index] }}
{% endfor %}

Can you show me some samples of how you want it to look like?

Thank you. Here is the test data I used.
{
“jobs”: [“Job A”, “Job B”, “Job C”],
“names”: [ [“Joe S”, “Jane B”, “Mike S”],
[“Joe S”, “Jane B”, “Mike S”, “Sue B”],
[“Joe S”, “Jane B”, “Mike S”]
],
“hours”: [ [10.50, 8.25, 12.00],
[9.00, 11.75, 8.50, 10.25],
[7.75, 6.50, 9.00]
],
“totals”: [ [30.75],
[39],
[23.25]
]
}

So would the result for an “item” look like:

Job A
Joe S, Jane B, Mike S

Timecard Name Timecard Hours
Joe S 10.50
Jane B 8.25
Mike S 12.00
Total 30.75

No need for the names below the Job. Just the list items. Thanks.

Job A

Timecard Name Timecard Hours
Joe S 10.50
Jane B 8.25
Mike S 12.00
Total 30.75

Just making sure you got my last reply.

Sorry I haven’t had much time to work on this. What I think you can do is have a joined list for the individual timecards, then create a rollup for the total, make a template for the “total” line, and combine them all together with another template column (joined list first, then total last).

no problem…Thanks!

Can you try the method above and let me know if it works? Basically my idea is to separate the single items, which you already have as rows, and then use a rollup + template column to construct the “total” row.

My issue is where in the pdf code to put the Glide templates.

Wouldn’t you have to combine the templates of each “job” together first before putting it wherever you like in PDFMonkey?