# Error: Object has no attribute 'id'

**URL:** <https://forum.inductiveautomation.com/t/error-object-has-no-attribute-id/95209>\
**Category:** Ignition\
**Tags:** perspective, ignition81, scripting\
**Created:** [August 27, 2024, 1:40pm UTC](https://forum.inductiveautomation.com/t/error-object-has-no-attribute-id/95209 "2024-08-27T13:40:06Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![ahawes](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ahawes/32/36337_2.png) [@ahawes](https://forum.inductiveautomation.com/u/ahawes)\
**Post date:** [August 27, 2024, 1:40pm UTC](https://forum.inductiveautomation.com/t/error-object-has-no-attribute-id/95209/1 "2024-08-27T13:40:06Z")

</div>

Good morning Team,

I am running an update query on a table and i am getting an error. I see where the error is happening but not sure on how to correct.

Query to populate the tabel:

```python
SELECT id, case_type, chute, chute_area, target, ordered, state
FROM chutes

```

Query to update the tabel:

```python
UPDATE `Clemens`.`chutes` SET `case_type` = :case_Type , `target` = :targetQTY , `state` = :stateAvail WHERE (`id` = :iD );

```

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

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

Configure on Action Performed

```python
def runAction(self, event):
	import time
	    	
	case_type = self.getSibling("Table").props.selection.data[0].case_type
	target = self.getSibling("Table").props.selection.data[0].target
	state = self.getSibling("Table").props.selection.data[0].state
	id = self.getSibling("Table").props.selection.data[0].id
	category = "HMI"
	source = "ASCADA Client"
	usr = self.session.props.auth.user.id
	message = str(usr) + " Inserted " + str(case_type), str(target) + " in WCS "
	data9 = usr	
				# Insert new SKU
	system.db.runNamedQuery("Tables/Chutes_Updates",{
			"caseType": case_type,
	    	"targetQTY": target,
	    	"stateAvail": state,
	    	"iD": id
	    	})
	    
	time.sleep(2)
	    	
	   	# Refresh table data
	self.getSibling("Table").refreshBinding()
	    					
		#Update Syslog		
	system.db.runNamedQuery("Tables/syslog_update",{
			"category": category,
	    	"source": source,
	    	"message": message,
	    	"data9": data9
	    	})
	time.sleep(2)				
	    
	self.getSibling("Table").props.selection.data[0].case_type= " "
	self.getSibling("Table").props.selection.data[0].target= " "
	self.getSibling("Table").props.selection.data[0].state= " "
	self.getSibling("Table").props.selection.data[0].id= " "

```

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

---

<div class="post-metadata">

**Author:** ![Benjamin\_Furlani](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/benjamin_furlani/32/66084_2.png) [@Benjamin\_Furlani](https://forum.inductiveautomation.com/u/Benjamin_Furlani)\
**Post date:** [August 27, 2024, 1:43pm UTC](https://forum.inductiveautomation.com/t/error-object-has-no-attribute-id/95209/2 "2024-08-27T13:43:59Z")

</div>

> [@ahawes](#):
>
> `id = self.getSibling("Table").props.selection.data[0].id`

does selection.data[0] actually have an id attribute in it in the designer for example? or you could system.perspective.log it.

You may need to include it as a column but then hide the column from the table in the columns property in the property tree

---

<div class="post-metadata">

**Author:** ![ahawes](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ahawes/32/36337_2.png) [@ahawes](https://forum.inductiveautomation.com/u/ahawes)\
**Post date:** [August 27, 2024, 1:47pm UTC](https://forum.inductiveautomation.com/t/error-object-has-no-attribute-id/95209/3 "2024-08-27T13:47:05Z")

</div>

> [@Benjamin\_Furlani](#):
>
> does selection.data[0] actually have an id attribute in it in the designer for example? or you could system.perspective.log it.

There is an id, that does not change, but is used to udpate that row's information.

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

I had the column in the table, hidden.

Here is is unhidden.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/8/8/883a1f99e5fc9184ebe3c71b994e003ebadd2d5f.png)

---

<div class="post-metadata">

**Author:** ![Benjamin\_Furlani](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/benjamin_furlani/32/66084_2.png) [@Benjamin\_Furlani](https://forum.inductiveautomation.com/u/Benjamin_Furlani)\
**Post date:** [August 27, 2024, 1:48pm UTC](https://forum.inductiveautomation.com/t/error-object-has-no-attribute-id/95209/4 "2024-08-27T13:48:56Z")

</div>

so if you `system.perspective.print(self.getSibling("Table").props.selection.data[0])`  
what is the browser consoles output?

---

<div class="post-metadata">

**Author:** ![ahawes](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ahawes/32/36337_2.png) [@ahawes](https://forum.inductiveautomation.com/u/ahawes)\
**Post date:** [August 27, 2024, 1:50pm UTC](https://forum.inductiveautomation.com/t/error-object-has-no-attribute-id/95209/5 "2024-08-27T13:50:30Z")

</div>

> [@Benjamin\_Furlani](#):
>
> system.perspecitve.print(self.getSibling("Table").props.selection.data[0])

Traceback (most recent call last):  
File "", line 1, in   
AttributeError: 'com.inductiveautomation.ignition.designer.gui.tool' object has no attribute 'perspecitve'

Also, as a note the ID is configured to the PLC array index.

---

<div class="post-metadata">

**Author:** ![Benjamin\_Furlani](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/benjamin_furlani/32/66084_2.png) [@Benjamin\_Furlani](https://forum.inductiveautomation.com/u/Benjamin_Furlani)\
**Post date:** [August 27, 2024, 1:52pm UTC](https://forum.inductiveautomation.com/t/error-object-has-no-attribute-id/95209/6 "2024-08-27T13:52:20Z")

</div>

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/d/0/d0a8108a844b6467a96e8f9a58301e93d45766f0.png)  
that error does not make sense to me if you are using this in an event handler...

---

<div class="post-metadata">

**Author:** ![Benjamin\_Furlani](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/benjamin_furlani/32/66084_2.png) [@Benjamin\_Furlani](https://forum.inductiveautomation.com/u/Benjamin_Furlani)\
**Post date:** [August 27, 2024, 1:52pm UTC](https://forum.inductiveautomation.com/t/error-object-has-no-attribute-id/95209/7 "2024-08-27T13:52:43Z")

</div>

> [@ahawes](#):
>
> 'perspecitve'

You misspelled

as did I originally

---

<div class="post-metadata">

**Author:** ![ahawes](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ahawes/32/36337_2.png) [@ahawes](https://forum.inductiveautomation.com/u/ahawes)\
**Post date:** [August 27, 2024, 2:06pm UTC](https://forum.inductiveautomation.com/t/error-object-has-no-attribute-id/95209/8 "2024-08-27T14:06:22Z")

</div>

I changed the row to show as visible and it looks like it is running but it did not update the tabel.

---

<div class="post-metadata">

**Author:** ![ahawes](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ahawes/32/36337_2.png) [@ahawes](https://forum.inductiveautomation.com/u/ahawes)\
**Post date:** [August 27, 2024, 2:24pm UTC](https://forum.inductiveautomation.com/t/error-object-has-no-attribute-id/95209/9 "2024-08-27T14:24:31Z")

</div>

Now when I execute the command it does not update.

I have changed the udpate query to use the values and it only works with the 'state' is in ' ' like 'Available'.

```python
UPDATE `Clemens`.`chutes` 
SET `case_type` = :case_Type , `target` = :targetQTY , `state` = :stateAvail
WHERE (`id` = :iD );

```

```python
UPDATE `Clemens`.`chutes` 
SET `case_type` = 102 , `target` = 222 , `state` = 'Available'
WHERE (`id` = 2 );

```

How do I fix that in my change script so it puts the 'state' in quotes?

---

<div class="post-metadata">

**Author:** ![ahawes](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ahawes/32/36337_2.png) [@ahawes](https://forum.inductiveautomation.com/u/ahawes)\
**Post date:** [August 27, 2024, 3:14pm UTC](https://forum.inductiveautomation.com/t/error-object-has-no-attribute-id/95209/10 "2024-08-27T15:14:07Z")

</div>

Anyone have an idea?

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [August 27, 2024, 3:23pm UTC](https://forum.inductiveautomation.com/t/error-object-has-no-attribute-id/95209/11 "2024-08-27T15:23:36Z")

</div>

I see `sleep(2)` twice in that script, so I'll suggest that the whole thing needs to be reworked.

Can you explain what you need to do ?

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [August 27, 2024, 3:26pm UTC](https://forum.inductiveautomation.com/t/error-object-has-no-attribute-id/95209/12 "2024-08-27T15:26:58Z")

</div>

> [@ahawes](#):
>
> How do I fix that in my change script so it puts the 'state' in quotes?

You shouldn't need them, passing parameters of the correct type to the named query will do that for you.

What flavor of DB are you using? You should not have Single Quotes around your column names.

I would expect your query to look like this:

```python
UPDATE Clemens.chutes
SET case_type = :case_Type, target = :targetQTY, state = :stateAvail
WHERE id = :iD

```

Notice the lack of back ticks and quotes.

Looking at your script, I see you are using time.sleep. This is a big no, no. Don't do it, you're tanking your performance as well as potentially creating other issues. You just do not need a forced delay here as `system.db.runNamedQuery()` is a blocking function so the rest of the code will not execute until it has returned anyway.

Also, you are using id as a variable name, it is a builtin and should not be used like this.

And might I suggest that rather than using a space `" "` for "Empty", use a value that is appropriate for the column type.

I would expect your script to look something like this:

```python
case_type = self.getSibling("Table").props.selection.data[0].case_type
target = self.getSibling("Table").props.selection.data[0].target
state = self.getSibling("Table").props.selection.data[0].state
rowId = self.getSibling("Table").props.selection.data[0].id

args = {
        "caseType":case_type,
        "targetQTY":target,
        "stateAvail":state,
        "iD":rowId
        }
system.db.runNamedQuery("Tables/Chutes_Updates", args)

self.getSibling("Table").refreshBinding()

userID = self.session.props.auth.user.id

system.db.runNamedQuery("Tables/syslog_update",{
        "category":"HMI",
        "source":"ASCADA Client",
        "message":"{} Inserted {}, {} in WCS".format(userId, case_type, target)
        "data9":userID
        })
self.getSibling("Table").props.selection.data[0].case_type = 0
self.getSibling("Table").props.selection.data[0].target = 0
self.getSibling("Table").props.selection.data[0].state = ""
self.getSibling("Table").props.selection.data[0].id = None

```

Ideally the majority of this script would probably be a library function that was called from a message handler on the table, rather than run in the event on the button.

---

<div class="post-metadata">

**Author:** ![ahawes](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ahawes/32/36337_2.png) [@ahawes](https://forum.inductiveautomation.com/u/ahawes)\
**Post date:** [August 27, 2024, 3:31pm UTC](https://forum.inductiveautomation.com/t/error-object-has-no-attribute-id/95209/13 "2024-08-27T15:31:54Z")

</div>

how would teh message handler look?

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [August 27, 2024, 3:37pm UTC](https://forum.inductiveautomation.com/t/error-object-has-no-attribute-id/95209/14 "2024-08-27T15:37:32Z")

</div>

I imagine that it would look something like this:

```python
def onMessageReceived(self, payload):
	lib.updateChutes(self.props.selection.data[0])
	self.refreshBinding()

```

---

<div class="post-metadata">

**Author:** ![Benjamin\_Furlani](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/benjamin_furlani/32/66084_2.png) [@Benjamin\_Furlani](https://forum.inductiveautomation.com/u/Benjamin_Furlani)\
**Post date:** [August 27, 2024, 3:39pm UTC](https://forum.inductiveautomation.com/t/error-object-has-no-attribute-id/95209/15 "2024-08-27T15:39:31Z")

</div>

> [@lrose](#):
>
> What flavor of DB are you using? You should not have Single Quotes around your column names

I just now noticed the backtics myself. you can use "columnName" for most SQL as well as [columnName]

---

<div class="post-metadata">

**Author:** ![ahawes](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ahawes/32/36337_2.png) [@ahawes](https://forum.inductiveautomation.com/u/ahawes)\
**Post date:** [August 28, 2024, 12:20pm UTC](https://forum.inductiveautomation.com/t/error-object-has-no-attribute-id/95209/16 "2024-08-28T12:20:43Z")

</div>

lrose, thanks so much for helping.

I have everything set but one field is not updating, the case\_type.

Here is the code to run the update and they query in perspective.

I believe it is a formatting issue. When I run the query it puts a null in this column.

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

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/2/b/2b4bf5e0018231160a37df7d0bc5b3d8c9b6adb3.png)

```python
UPDATE Clemens.chutes
SET case_type = :case_Type, target = :targetQTY, state = :stateAvail
WHERE id = :iD

```

```python
def runAction(self, event):
	    	
	case_type = self.getSibling("Case Type").props.value
	target = self.getSibling("Quantity").props.value
	state = self.getSibling("Status").props.value
	rowid = self.getSibling("Table").props.selection.data[0].id
	category = "HMI"
	source = "ASCADA Client"
	usr = self.session.props.auth.user.id
	message = str(usr) + " Inserted " + str(case_type), str(target) + " in WCS "
	data9 = usr	
				# Insert new SKU
	system.db.runNamedQuery("Tables/Chutes_Updates",{
			"caseType": case_type,
	    	"targetQTY": target,
	    	"stateAvail": state,
	    	"iD": rowid
	    	})
	    
	    	
	   	# Refresh table data
	self.getSibling("Table").refreshBinding("props.data")
	    					
		#Update Syslog		
	system.db.runNamedQuery("Tables/syslog_update",{
			"category": category,
	    	"source": source,
	    	"message": message,
	    	"data9": data9
	    	})
	   
	self.getSibling("Table").props.selection.data[0].case_type = ""
	self.getSibling("Table").props.selection.data[0].target = ""
	self.getSibling("Table").props.selection.data[0].state = ""
	self.getSibling("Table").props.selection.data[0].id = None    

```

---

<div class="post-metadata">

**Author:** ![ahawes](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ahawes/32/36337_2.png) [@ahawes](https://forum.inductiveautomation.com/u/ahawes)\
**Post date:** [August 28, 2024, 12:23pm UTC](https://forum.inductiveautomation.com/t/error-object-has-no-attribute-id/95209/17 "2024-08-28T12:23:00Z")

</div>

In addtion, i have my drop down options reading from a tabel to populate the qeury.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/3/0/3078101c3738c1d9c0eea97d97ba9f11b30dc064.png)

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [August 28, 2024, 12:42pm UTC](https://forum.inductiveautomation.com/t/error-object-has-no-attribute-id/95209/18 "2024-08-28T12:42:51Z")

</div>

The key in your params dictionary must match exactly what you have set up in the Named Query.

so `"caseType"` should be `"case_Type"`. That was how you had it in your original script, and I didn't check it against the parameter names.

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [August 28, 2024, 1:31pm UTC](https://forum.inductiveautomation.com/t/error-object-has-no-attribute-id/95209/19 "2024-08-28T13:31:40Z")

</div>

I'd change the parameter in the named query to `caseType`, to be consistent with the other parameters.
