Perspective write to database

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:

Here is my script so far.

		
	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.

I’ve also tried this script:

	
	
	# 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:

Any suggestions?

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

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.

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

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

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

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

Awesome, thanks for the help! @pturmel