# Issue passing selected row data to a pop-up

**URL:** <https://forum.inductiveautomation.com/t/issue-passing-selected-row-data-to-a-pop-up/99709>\
**Category:** Ignition\
**Created:** [December 11, 2024, 8:01pm UTC](https://forum.inductiveautomation.com/t/issue-passing-selected-row-data-to-a-pop-up/99709 "2024-12-11T20:01:15Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![dis](https://avatars.discourse-cdn.com/v4/letter/d/e99b99/32.png) [@dis](https://forum.inductiveautomation.com/u/dis)\
**Post date:** [December 11, 2024, 8:01pm UTC](https://forum.inductiveautomation.com/t/issue-passing-selected-row-data-to-a-pop-up/99709/1 "2024-12-11T20:01:15Z")

</div>

I have a display that has a table that is populated by a gateway script. It serves a debug log from the scripting.

It has up to 25 rows and 3 columns (ID , Message , TimeStamp)  
an example row would be  
00000000005008675309 Duplicate 12/11 08:00

I created an event on the table

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/e/6/e636130f8199721332f570d2676de94b8160b032.png)

value is {/root/Table.props.selection.data[0].ID}

The "popup" view is simply just a table and the data is linked to a named query.  
The view has a parameter named key.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/5/f/5f02d05c65f53729fdfb857cd3dbabc86e01ab72.png)

I have tested the the named query using 00000000005008675309 and it returns the correct records

Here is the popup screen and value being passed into the pop-up. It's just a label on the screen, however the data being returned is a different record (I expect 3 records so that's ok).

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/9/a/9a61845feadb9bcc34aa2c242b499305c0086eab.png)

The ID field is defined as char(20) in the SQL database. I'm not sure exactly what's going on but it seems like there's data conversion happening behind the scenes.

---

<div class="post-metadata">

**Author:** ![ryan.white](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ryan.white/32/73193_2.png) [@ryan.white](https://forum.inductiveautomation.com/u/ryan.white)\
**Post date:** [December 11, 2024, 8:37pm UTC](https://forum.inductiveautomation.com/t/issue-passing-selected-row-data-to-a-pop-up/99709/2 "2024-12-11T20:37:27Z")

</div>

It might be that the `props.selection` data has not populated with the correct data by the time the event is called.

What happens if you try double clicking on one line, then closing the popup and double clicking on a different line? Do you get the previously selected line's data?

Try adding a label to the popup that has its text bound to `{view.params.key}` so you can sanity check what is actually being passed.

Also, for what it is worth, I can never seem to get the popup action to do what I want, so I use a script action instead and use [`system.perspective.openPopup`](https://www.docs.inductiveautomation.com/docs/8.1/appendix/scripting-functions/system-perspective/system-perspective-openPopup) to script the opening of my popups. It gives you a lot more control.

---

<div class="post-metadata">

**Author:** ![dis](https://avatars.discourse-cdn.com/v4/letter/d/e99b99/32.png) [@dis](https://forum.inductiveautomation.com/u/dis)\
**Post date:** [December 12, 2024, 2:49pm UTC](https://forum.inductiveautomation.com/t/issue-passing-selected-row-data-to-a-pop-up/99709/3 "2024-12-12T14:49:39Z")

</div>

I didn't think about it being a 'late data arrival' issue. But, it doesn't give me the previously selected one. What's interesting is that I have another pop-up that does a query to a different table using a different value and that works fine. I'll work with our DBA to see if we can capture the query on the SQL side. I changed the action to a script and added some debugging.

```python
def runAction(self, event):
	try:
		dict =event.value 
		vID = dict['ID']
		params = {"vID":vID}
		system.db.runNamedQuery("INSERT_DEBUG", params)
		system.perspective.openPopup ('DogLog',"Templates/Table",params)
		
	except Exception as e:
		vID = str(e)
		params = {"vID":vID}
		system.db.runNamedQuery("INSERT_DEBUG", params)

```

My SQL debug table has the correct value being passed  
The pop-up shows the query runs and I get the wrong data.  
I even went so far as to change the query to like '%' + ID + '%'

---

<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:** [December 12, 2024, 2:56pm UTC](https://forum.inductiveautomation.com/t/issue-passing-selected-row-data-to-a-pop-up/99709/4 "2024-12-12T14:56:47Z")

</div>

Python's `Exception` class doesn't include the panoply of java exceptions that can occur, particularly any SQLException that JDBC can throw. You should include another `except Throwable, t:` clause for those, where you include a

```python
from java.lang import Throwable

```

above your `try:`. (Preferably in a project library script where you delegate your event and action scripts, so it can be imported as a persistent global.)

Also, note that stringifying an exception loses the traceback, which is a real problem for java exceptions, since the traceback has any chained "caused by" inner exceptions. You should **log** your exceptions, using the logger methods that take a `Throwable`.

---

<div class="post-metadata">

**Author:** ![dis](https://avatars.discourse-cdn.com/v4/letter/d/e99b99/32.png) [@dis](https://forum.inductiveautomation.com/u/dis)\
**Post date:** [December 12, 2024, 3:03pm UTC](https://forum.inductiveautomation.com/t/issue-passing-selected-row-data-to-a-pop-up/99709/5 "2024-12-12T15:03:04Z")

</div>

Thanks. I was going to fix that but right now it's just a quick catch while I'm debugging.

I changed my Named Query and added

```python
INSERT INTO debug ([QueryText]) 
VALUES (:vID)
Select .... from ...where ...

```

My debug table has the correct value and I can use that value in SMMS to do a select query and get the correct records. This is just weird.

Going to try some things on the pop-up screen to troubleshoot.  
I set the binding on the table to a property view.params.vID  
Then I added the following transform script

```python
	from java.lang import Throwable
	try:
		vID = value
		params = {"vID":vID}
		dbdata = system.db.runNamedQuery("IDLookup", params)
		
		return dbdata
	
	except java.lang.Throwable, e:
		vID = str(e.cause)
		params = {"vID":vID}
		system.db.runNamedQuery("INSERT_DEBUG", params)
				
	except Exception as e:
		vID = str(e)
		params = {"vID":vID}
		system.db.runNamedQuery("INSERT_DEBUG", params)
														

```

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/5/1/51b5558efa7bc9d296a524ee269964a7a5cc18ad.png)  
Dataset has wrong data.

Got rid of the named query and tried running with and without debug.  
Debug table shows the correct value.  
Table shows wrong data.

```python
	from java.lang import Throwable
	try:
		query = "Select * FROM [myDB] where [vID]=" + "'"+ value + "'" 
		dbdata = system.db.runQuery(query,'myDB')
	
		params = {"vID":query}
		system.db.runNamedQuery("INSERT_DEBUG", params)
		return dbdata
	
	except java.lang.Throwable, e:
		vID = str(e.cause)
		params = {"vID":vID}
		system.db.runNamedQuery("INSERT_DEBUG", params)
				
	except Exception as e:
		vID = str(e)
		params = {"vID":vID}
		system.db.runNamedQuery("INSERT_DEBUG", params)														

```

My debug table has the correct record  
Select \* FROM [myDB] where [vID]='00000000005008675309'

---

<div class="post-metadata">

**Author:** ![ryan.white](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ryan.white/32/73193_2.png) [@ryan.white](https://forum.inductiveautomation.com/u/ryan.white)\
**Post date:** [December 12, 2024, 8:44pm UTC](https://forum.inductiveautomation.com/t/issue-passing-selected-row-data-to-a-pop-up/99709/6 "2024-12-12T20:44:11Z")

</div>

Personal gripe here, your ID columns really should be INT or BIGINT and formatted at point of use/display to have the preceding zeros.

What about the dataset is wrong? Just completely different records from a different ID? Or is it the correct ID and missing some rows?

---

<div class="post-metadata">

**Author:** ![dis](https://avatars.discourse-cdn.com/v4/letter/d/e99b99/32.png) [@dis](https://forum.inductiveautomation.com/u/dis)\
**Post date:** [December 13, 2024, 12:53pm UTC](https://forum.inductiveautomation.com/t/issue-passing-selected-row-data-to-a-pop-up/99709/7 "2024-12-13T12:53:07Z")

</div>

This "ID" is part of a much larger system that I have not given you information about so while your point is valid it doesn't work in the "big picture". But given the choice I would have made it a number and did post-processing also.

At this point all the logic is in the popup. The scripting is all in the table object. The data is bound to the incoming parameter which is then transformed in the script.

For ease typing the input string is a 20 character number (prepended with 0). In my examples I'll use 'generic' 7 digit numbers as a representation.

All indications show that when I search for record 8675309 I'm returned a completely different record. I'm trying to figure out how 8675309 is getting 'translated' to something completely different in the query either by Ignition or MSSQL. This mistranslation, as I'll call it occurs for any value that is queried. If I were to query 4894608 I'll get records for 5552303 returned.

The recordset that is returned is 'correct' for that ID it's just the wrong ID. I.E. if I manually query 5552303 in SMMS I get the same recordset that was returned by Ignition querying 4894608

I have not been able to manually cause this mistranslation so I don't know if something is converting a string to number and hitting a boundary or what.

If I run the following in the script console I get the correct records

```python
try:
	value = '00000000008508675309'
	query = "Select * FROM [Table] where [ID]=" + "'"+ value + "'" 
	dbdata = system.db.runQuery(query,'AutoLabel')
	for row in range(dbdata.getRowCount()):
	    for col in range(dbdata.getColumnCount()):
	        print dbdata.getValueAt(row, col)
except Exception as e:
	print str(e)

```

---

<div class="post-metadata">

**Author:** ![dis](https://avatars.discourse-cdn.com/v4/letter/d/e99b99/32.png) [@dis](https://forum.inductiveautomation.com/u/dis)\
**Post date:** [December 13, 2024, 1:21pm UTC](https://forum.inductiveautomation.com/t/issue-passing-selected-row-data-to-a-pop-up/99709/8 "2024-12-13T13:21:56Z")

</div>

At this point in the story we see where the user made a terrible mistake in interpreting the resultant data as displayed.  
I clicked icon to see the raw table data  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/f/8/f86df229a14fab1764b4343aaa480ce733d4a895.png)  
and realized that the Table object is not spacing the columns and the ID and the next field are overlapping. 🤦‍♂️ I was only seeing the the first ## characters of the ID and the next 7 characters of the next field all bunched together in the popup table.

0080011100225049757

008001110022508675309 49757

Not the dumbest mistake I every made.
