# PDF Creation Passing Data In Issues

**URL:** <https://forum.inductiveautomation.com/t/pdf-creation-passing-data-in-issues/70942>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [March 12, 2023, 1:32am UTC](https://forum.inductiveautomation.com/t/pdf-creation-passing-data-in-issues/70942 "2023-03-12T01:32:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tyler\_Folsom](https://avatars.discourse-cdn.com/v4/letter/t/8797f3/32.png) [@Tyler\_Folsom](https://forum.inductiveautomation.com/u/Tyler_Folsom)\
**Post date:** [March 12, 2023, 1:32am UTC](https://forum.inductiveautomation.com/t/pdf-creation-passing-data-in-issues/70942/1 "2023-03-12T01:32:20Z")

</div>

Hello,

I am getting close but not quite there. I have been at this problem for a few days so I decided it was time to reach out here. What I am trying to do is pass multiple IDs from a table (originated from a database) into a query that will display the ticket information into a PDF.

What I have so far is a table that calls a popup that then initiates a report. This is working with hardcoded ticket IDs.

--I apologize right here because I don't know how to frame my question well.--

I am slowly working my way, step by step, to the end goal. Where I am at now is between the popup screen and the PDF report creation. I think I am passing a dataset but on the report side I am unsure how to utilize it. I have a for loop that builds the WHERE clause for the query.  
For example: **ticket\_ids = ticket\_ids + " OR t1.id = " + str(73555)**...so on and so forth

First question is how to do I find the number of rows being pass through idList2?  
I have watched a few videos and this one was particularly helpful ([Scripting Data Source Video at Inductive University](https://inductiveuniversity.com/videos/scripting-data-source/8.1)). I am still missing something.

Passing out idList2 as a dataset.

 ![01 TicketReport Popup (idList2 dataset)](https://us1.discourse-cdn.com/inductiveautomation/original/3X/2/4/2400d9074cc1f265d1f30804883ae12e554d6ecb.jpeg)

Hardcoding the dataset inside the popup's parameters.  
5 Rows x 1 Column

 ![02 Building the dataset](https://us1.discourse-cdn.com/inductiveautomation/original/3X/7/7/7746d3f818e0f1b3683cd59207cb4a8c185a135f.jpeg)

The dataset **(idList2)** LIVES 😄

 ![03 View of dataset](https://us1.discourse-cdn.com/inductiveautomation/original/3X/a/3/a37b5dcd166f565753e7e65c84c87502cd467444.png)

Scipt inside the report. The query in the script works. Where I am stuck is how to find the length of idList2. From there, I am sure it will become clear how I can put the ticket ID from the dataset.

 ![04 TicketPDF](https://us1.discourse-cdn.com/inductiveautomation/original/3X/c/8/c8c30897c8cbc88dd96a76a78796f33727145277.png)

Thought on this one?  
Cheers fellow Perspective friends and happy weekend!

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [March 12, 2023, 9:23am UTC](https://forum.inductiveautomation.com/t/pdf-creation-passing-data-in-issues/70942/2 "2023-03-12T09:23:32Z")

</div>

> [@Tyler\_Folsom](#):
>
> I have a for loop that builds the WHERE clause for the query.  
> For example: **ticket\_ids = ticket\_ids + " OR t1.id = " + str(73555)**...so on and so forth

Don't do that. If you can script the construction of a where clause, you can construct it with parameter placeholders and pass the parameters without string conversion. You would have code something like this:

```auto
	idList = list(data['idList2'].getColumnAsList(0))
	if idList:
		if len(idList) > 1:
			q_where = "ticket_ids IN (%s)" % (', '.join(['?'] * len(idList)))
		else:
			q_where = "ticket_ids = ?"
	else:
		q_where = "0=1"
	sql_query = "Select ...... From tickets Where %s" % q_where
	pyds = system.db.runPrepQuery(sql_query, idList, 'myDB')
	data['tickets'] = pyds.underlyingDataset

```

If you need subqueries to go with each ticket, it gets more complicated:

> [@Report with Scripted Nested Data](https://forum.inductiveautomation.com/t/report-with-scripted-nested-data/11801):
>
> The report datasource scripting examples explain how to access the nested data in another key for use constructing a custom dataset. What I don’t see is how to construct nested data that would be suitable for use with a child table in a table group. I have a parent dataset that I’m constructing via script due to annoying limitations of an ancient SQL Server 2000 instance. I need a subquery for each row that could be done with a normal query, but there’s no way to add a regular subquery to a s…

---

<div class="post-metadata">

**Author:** ![Tyler\_Folsom](https://avatars.discourse-cdn.com/v4/letter/t/8797f3/32.png) [@Tyler\_Folsom](https://forum.inductiveautomation.com/u/Tyler_Folsom)\
**Post date:** [March 14, 2023, 4:08am UTC](https://forum.inductiveautomation.com/t/pdf-creation-passing-data-in-issues/70942/3 "2023-03-14T04:08:34Z")

</div>

I want to thank you for your suggestions. I am running them and making progress.  
So far your methods have been implemented into the report and are working 👌

On Tuesday, I will work on removing the hardcodes ticket IDs to replace them with ones passed in through a another SQL query.

Thanks again!!
