# Vision scripting issue

**URL:** <https://forum.inductiveautomation.com/t/vision-scripting-issue/78953>\
**Category:** Ignition\
**Tags:** ignition81, vision, scripting, database\
**Created:** [September 11, 2023, 7:25am UTC](https://forum.inductiveautomation.com/t/vision-scripting-issue/78953 "2023-09-11T07:25:18Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Surya\_Chandra\_Mohan](https://avatars.discourse-cdn.com/v4/letter/s/a9adbd/32.png) [@Surya\_Chandra\_Mohan](https://forum.inductiveautomation.com/u/Surya_Chandra_Mohan)\
**Post date:** [September 11, 2023, 7:25am UTC](https://forum.inductiveautomation.com/t/vision-scripting-issue/78953/1 "2023-09-11T07:25:18Z")

</div>

Hello,  
I am trying to perform delete operation in a table using database and script.  
I am trying to call a named query through scripting, but there's an error saying Transaction databaseName is closed  
If I try to include the args as list, I will get another error saying Cannot coerce value '[{'sensor\_id': 12}]' into type: interface java.util.Map

Can you please help me out with this issue

table = event.source.parent.getComponent('Table')  
selectedRow = table.getSelectedRow()

if selectedRow \>= 0:  
data = (table.data).getValueAt(selectedRow, 'sensor\_id')

```
# Ask for confirmation
confirmed = system.gui.confirm("Are you sure you want to delete the selected row?")
if confirmed:
    args = {'sensor_id': data} # Using a dictionary for named parameters
    event.source.parent.getComponent('Label').text = str(selectedRow) + str(data)

    # Delete from database using the named query
    query = "displayDeleteUser"
    result = system.db.runNamedQuery("displayDeleteUser", args, "databaseName")

    system.db.refresh(event.source.parent.getComponent('Table'), "data")
else:
    print("Deletion cancelled.")

```

else:  
system.gui.errorBox("Please Select a Row to Delete", "Selection Error")

---

<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:** [September 11, 2023, 7:30am UTC](https://forum.inductiveautomation.com/t/vision-scripting-issue/78953/2 "2023-09-11T07:30:43Z")

</div>

Well... You're just not using the function properly.

Look at the doc:  
[https://docs.inductiveautomation.com/display/DOC81/system.db.runNamedQuery](https://docs.inductiveautomation.com/display/DOC81/system.db.runNamedQuery)

The function's third argument is either `tx` or `parameters`, depending on the scope.  
From the error you're getting, it is clear that you're calling the function in the client/session scope, and that it expects the third argument to be a transaction id.  
Remove the third argument and you'll be fine.

PS: the database used by named queries are defined by the named query itself, not by the function that calls it.  
PPS: Try to find a better title next time. This one says absolutely nothing about the issue you have: 2 out of the 3 words are already in the tags, and the last one, well... you probably wouldn't be posting if everything was fine.

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [September 11, 2023, 7:38am UTC](https://forum.inductiveautomation.com/t/vision-scripting-issue/78953/3 "2023-09-11T07:38:00Z")

</div>

> [@Surya\_Chandra\_Mohan](#):
>
> table = event.source.parent.getComponent('Table')  
> selectedRow = table.getSelectedRow()

See here on how to post code on the forum. (The first four lines of code are not formatted properly.)

> [@Wiki - how to post code on this forum](https://forum.inductiveautomation.com/t/wiki-how-to-post-code-on-this-forum/77831):
>
> This thread is intended as a short help file for all those struggling to post formatted code on the forum. Posting formatted code on the forum (and most others) is as simple as selecting the code and pressing the \</\> button. It works the same as applying Bold or Italic styles to your document. It preserves indentation and applies syntax highlighting. [How to post code]

There's a pencil icon under your post which will allow you to edit it - and fix the title.

---

<div class="post-metadata">

**Author:** ![Surya\_Chandra\_Mohan](https://avatars.discourse-cdn.com/v4/letter/s/a9adbd/32.png) [@Surya\_Chandra\_Mohan](https://forum.inductiveautomation.com/u/Surya_Chandra_Mohan)\
**Post date:** [September 11, 2023, 7:39am UTC](https://forum.inductiveautomation.com/t/vision-scripting-issue/78953/4 "2023-09-11T07:39:17Z")

</div>

Thank you! It is working now!

And apologies for title which is used!

---

<div class="post-metadata">

**Author:** ![Surya\_Chandra\_Mohan](https://avatars.discourse-cdn.com/v4/letter/s/a9adbd/32.png) [@Surya\_Chandra\_Mohan](https://forum.inductiveautomation.com/u/Surya_Chandra_Mohan)\
**Post date:** [September 11, 2023, 7:39am UTC](https://forum.inductiveautomation.com/t/vision-scripting-issue/78953/5 "2023-09-11T07:39:45Z")

</div>

Thank you!  
Will have a look at it and post it properly the next time!
