Configured Event onActionPerformed Script Run NamedQuery

I am configuring an event script onActionPerformed of a Button that takes data that is input into Text Fields and Dropdown selections. When the button is pressed, it performs a system.db.runNamedQuery(path, params). The Named Query works perfect in the Testing function, however, the button script is not working. Below is the script. Any help figuring out what I am doing wrong would be greatly appreciated.

def runAction(self, event):
	dbConnection 	= "FRW_IGNITION_HIST"
	chillerID 		= self.parent.custom.ChillerID
	chillerName 	= self.getSibling("ChillerName").props.text
	wo       		= self.getSibling("WorkOrder").props.value
	fromTank        = self.getSibling("StartTank").props.value
	toTank 			= self.getSibling("EndTank").props.value
	extraTank1 		= self.getSibling("EndTank1").props.value
	extraTank2 		= self.getSibling("EndTank2").props.value
	lot 			= self.getSibling("LotNumber").props.text
	feedtype 		= self.getSibling("FeedType").props.text
	prodtempmin 	= self.getSibling("ProdTempMin").props.value
	prodtempmax 	= self.getSibling("ProdTempMin").props.value
	jobtype 		= self.getSibling("JobType").props.value
	status 			= self.getSibling("Status").props.value
	statusreason 	= self.getSibling("StatusReason").props.value
	comment 		= self.getSibling("Comments").props.text
	timestamp 		= self.getSibling("LogDate").props.text
	dt 				= self.getSibling("MonthYear").props.text
	tagPath 		= "Chillers_%s/Chiller_%s/WOLoaded"%(plantName,chillerName)
	user 			= self.session.props.auth.user.userName

	path = 	'Refrigeration/ChillerWOEntry'
	params = {'chillerID':ChillerID, 'chillerName':ChillerName,	'wo':WorkOrderNum, 'fromTank':StartTank, 'toTank':EndTank, 'extraTank1':EndTank1, 'extraTank2':EndTank2, 'lot':LotNumber, 'feedtype':FeedType, 'prodtempmin':ProdTempMin, 'prodtempmax':ProdTempMax, 'jobtype':JobType, 'status':Status, 'statusreason':StatusReason, 'comment':Comments, 'timestamp':LogDate, 'dt':DT, 'user':OperatorName}		
	system.db.runNamedQuery(str(path, params))

Thank you,
Jeremy

Please edit your post (pencil icon), select all of the code, then click the "preformatted text" button (</>).

What's the str() function there for?

Please see Wiki - how to post code on this forum. Post code - not pictures of code.

The (str()) was my latest attempt to make it work. I initially tried it without the (str*

Just a shot in the dark based on the little information given and the fact that I am rather new to all of this myself.

I think maybe you have reversed the order of your data and your named query's parameters. As an example, if the parameter defined in the named query is ChillerID and you want to used the value defined in the script chillerID, it should be


params = {'ChillerID' : chillerID,...}
2 Likes

You must have dark vision.

@Jeremy_Edwards1
The keys in the params dictionary must match with case sensitivity, the parameters that are used in the Authoring tab of the Named Query. Any parameter which doesn't match is ignored.

Also of note, youve created a variable to hold the database, but you are not providing that in your params dictionary. If you have set the named query to have a parameter provided database, then you must also include that in your prameters dictionary.

Change that, and remove the str() and you should get an expected result.

You could avoid all of this, if you used a custom property with a Named Query Binding, and then just refreshed the binding with the button. Will be more performant as well.

1 Like

@lrose ,
Thank you, I will go back through it and make any case corrections. I have already removed the (str().
Just for clarification: the {'key' :value} is like this correct?

`chillerName 	= self.getSibling("ChillerName").props.text`
'chillerName':ChillerName

key = chillerName
value = ChillerName

Here is the Named Query

INSERT INTO CH_Log( ChillerID, Comments, DT, EndTank, EndTank1, EndTank2, FeedType, JobType, LogDate, LotNumber, OperatorName, ProdTempMax, ProdTempMin, StartTank, Status, StatusReason, WorkOrderNum)
VALUES( :ChillerID, :Comments, :DT, :EndTank, :EndTank1, :EndTank2, :FeedType, :JobType, :LogDate, :LotNumber, :OperatorName, :ProdTempMax, :ProdTempMin, :StartTank, :Status, :StatusReason, :WorkOrderNum)

Consider also refactoring your code like this, to dramatically reduce duplication (and opportunities for typos to slip in):

def runAction(self, event):
    path = 'Refrigeration/ChillerWOEntry'
    params = {
        "chillerID": self.parent.custom.ChillerID,
        "chillerName": self.getSibling("ChillerName").props.text,
        "wo": self.getSibling("WorkOrder").props.value,
        "fromTank": self.getSibling("StartTank").props.value,
        "toTank": self.getSibling("EndTank").props.value,
        "extraTank1": self.getSibling("EndTank1").props.value,
        "extraTank2": self.getSibling("EndTank2").props.value,
        "lot": self.getSibling("LotNumber").props.text,
        "feedtype": self.getSibling("FeedType").props.text,
        "prodtempmin": self.getSibling("ProdTempMin").props.value,
        "prodtempmax": self.getSibling("ProdTempMin").props.value,
        "jobtype": self.getSibling("JobType").props.value,
        "status": self.getSibling("Status").props.value,
        "statusreason": self.getSibling("StatusReason").props.value,
        "comment": self.getSibling("Comments").props.text,
        "timestamp": self.getSibling("LogDate").props.text,
        "dt": self.getSibling("MonthYear").props.text,
        "user": self.session.props.auth.user.userName
    }
        
    system.db.runNamedQuery(path, params)

Consider also reading though this thread, especially this post in particular:

3 Likes

Do as @PGriffith showed, do note however, that you do need to match case and name.

So for instance, it should be:

"ChillerID" not "chillerId"

Also, you have used a "chillerName" parameter, but the query you have showed does not include that parameter.

@PGriffith probably did not take the time to check the validity of the parameters but rather was just trying to illustrate how to write the code in a best practice form.

3 Likes

Yeah, good catch. I just had Copilot translate the snippet, didn't look at it in any depth.

Indentation error

Sorry, meant to say, Corrected Indentation Error. :slightly_smiling_face: