# Perspective write to database

**URL:** <https://forum.inductiveautomation.com/t/perspective-write-to-database/61362>\
**Category:** Ignition\
**Tags:** ignition81, scripting, perspective\
**Created:** [June 29, 2022, 6:17pm UTC](https://forum.inductiveautomation.com/t/perspective-write-to-database/61362 "2022-06-29T18:17:04Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jay\_Whorton](https://avatars.discourse-cdn.com/v4/letter/j/a3d4f5/32.png) [@Jay\_Whorton](https://forum.inductiveautomation.com/u/Jay_Whorton)\
**Post date:** [June 29, 2022, 6:17pm UTC](https://forum.inductiveautomation.com/t/perspective-write-to-database/61362/1 "2022-06-29T18:17:04Z")

</div>

I’m on version 8.1.17

I’m working on an entry form in perspective. The goal is to have the user fill out a form (in a pop-up) and then write that data to a table in a database in SSMS.

Here is the form:

 ![EntryForm](https://us1.discourse-cdn.com/inductiveautomation/original/3X/2/6/2617dbb50a92727cfb86585393b6c2dbe874960e.png)

Here is my script so far.

```auto
		
	project = 'xxxxx'
	query = 'Insert Data'
	tx = None
	getKey = 1
	params = {
		'reg_date':self.getChild("EntryForm").getChild("Date TextField").props.text,
		'location':self.getChild("EntryForm").getChild("Location Dropdown").props.value,
		'lot_num':self.getChild("EntryForm").getChild("Lot Number TextField").props.text,
		'variety':self.getChild("EntryForm").getChild("Variety Dropdown").props.value,
		'issue':self.getChild("EntryForm").getChild("Issue TextField").props.text,
		'detail':self.getChild("EntryForm").getChild("Detail TextField").props.text,
		'kg':self.getChild("EntryForm").getChild("Kg TextField").props.text
	}
	
	
	key = system.db.runNamedQuery(project, query, params, [tx], [getKey])
	system.perspective.print(key, destination="gateway")
	id = key
	view = 'RTFTpopup'
	title = str(key) + 'Database record'
	position = {'width':800, 'height':800}
	
	system.perspective.openPopup(id, params, title, position, resizeable = True)

```

I’ve tried to remove the project in line : key = system.db.runNamedQuery(project, query, params, [tx], [getKey])

and it still doesn’t work.

This is the error that I’m getting.

 ![error1](https://us1.discourse-cdn.com/inductiveautomation/original/3X/7/7/77ec75014f5ce811c7d7268bf3210b76112f75b5.png)

I’ve also tried this script:

```auto
	
	
	# implement your method here	
	project = 'xxxxx'
	query = 'Insert Data'
	tx = None
	getKey = 1
	params = {
		'reg_date':self.getChild("EntryForm").getChild("Date TextField").props.text,
		'location':self.getChild("EntryForm").getChild("Location Dropdown").props.value,
		'lot_num':self.getChild("EntryForm").getChild("Lot Number TextField").props.text,
		'variety':self.getChild("EntryForm").getChild("Variety Dropdown").props.value,
		'issue':self.getChild("EntryForm").getChild("Issue TextField").props.text,
		'detail':self.getChild("EntryForm").getChild("Detail TextField").props.text,
		'kg':self.getChild("EntryForm").getChild("Kg TextField").props.text
	}
	
	key = system.db.runNamedQuery(query, params)
	#key = system.db.runNamedQuery(project, query, params, [tx], [getKey])
	system.perspective.print(key, destination="gateway")
	id = key
	view = 'RTFTpopup'
	title = str(key) + 'Database record'
	position = {'width':800, 'height':800}
	
	system.perspective.openPopup(id, params, title, position, resizeable = True)

```

In this script, I’m getting this error:

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

Any suggestions?

I’m not sure what the syntax error @P5 means.

---

<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:** [June 29, 2022, 6:23pm UTC](https://forum.inductiveautomation.com/t/perspective-write-to-database/61362/2 "2022-06-29T18:23:56Z")

</div>

Named query parameters use the syntax `:yourParamName` instead of `@yourParamName`

Also, is the parameter `kg` intended to be a boolean? It appears you’re providing a `[1]` for that parameter but it’s expecting a boolean.

---

<div class="post-metadata">

**Author:** ![Jay\_Whorton](https://avatars.discourse-cdn.com/v4/letter/j/a3d4f5/32.png) [@Jay\_Whorton](https://forum.inductiveautomation.com/u/Jay_Whorton)\
**Post date:** [June 29, 2022, 6:31pm UTC](https://forum.inductiveautomation.com/t/perspective-write-to-database/61362/3 "2022-06-29T18:31:45Z")

</div>

kg is intended to be a varchar. I have it set as a float8.

---

<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:** [June 29, 2022, 6:36pm UTC](https://forum.inductiveautomation.com/t/perspective-write-to-database/61362/4 "2022-06-29T18:36:09Z")

</div>

Replace `[getKey]` with `getKey=True` or `getKey=1`. By that I mean:

```auto
key = system.db.runNamedQuery(query, params, getKey=1)

```

`getKey` is a keyword parameter to the function call, not a parameter of your named query.

---

<div class="post-metadata">

**Author:** ![Jay\_Whorton](https://avatars.discourse-cdn.com/v4/letter/j/a3d4f5/32.png) [@Jay\_Whorton](https://forum.inductiveautomation.com/u/Jay_Whorton)\
**Post date:** [June 29, 2022, 6:53pm UTC](https://forum.inductiveautomation.com/t/perspective-write-to-database/61362/5 "2022-06-29T18:53:43Z")

</div>

Awesome, thanks for the help! @pturmel
