Global Name Not Defined

Good morning Team,

I have a table that I am trying to run using a ‘CLICK’ event. When I substitue the :lookLoc with an acutal location the script runs in test mode fine.

When I try to run the the :lookLoc I get this error.

Traceback (most recent call last):
File “function:runAction”, line 2, in runAction
NameError: global name ‘p’ is not defined

SELECT p.lpn AS "LPN", SUBSTRING(p.location, 2, 12) AS "ALOC", p.sku AS "SKU", p.lot_number AS "LOT", 
p.qc_status AS "QC Status",p.timestamp AS "Timestamp", p.quantity AS "Qty", p.sub_status AS "Sub Status", 
p.status  AS "Last Status", p.dest AS "Destination", p.reason_code AS "WCS Code", 
p.handstack AS "Hand-stack", dx.row_locked AS "Locked"
FROM Clemens.pallets p
LEFT OUTER JOIN dambach_xref dx ON dx.id = p.dambach_xref_id
WHERE dx.area = 2
AND p.dambach_xref_id BETWEEN 1 AND 999998
AND p.location =  :lookLoc 

That looks like a jython error. Which would be expected from a runAction. But your "code" is a SQL statement. Perhaps you should show us the entire script.

1 Like

Here is the script.

	p.location = self.view.params.LookupLoc
		
		
					# Look up location from click on ASRS pallet loc
	system.db.runNamedQuery("CFG Queries/asrs_pallet_lookup1",{
				"lookLoc": p.location			
						})
	
		
		
		# Refresh table data
	self.getSibling("ASRSlookLoc").refreshBinding("props.data")

If this is truly the entirety of the script then you haven't defined p anywhere...

Python doesn’t allow dots in variable names because the dot is the property lookup operator.

Thank you Phil,

How would I fix that on this join? Would I just use ‘location p’?

Use any variable name–just location perhaps. The variable name in jython doesn’t have to match the name in the Named Query. Just the dictionary key has to match lookLoc. The dictionary ties whatever constant or variable you wish to supply to the right place in the named query.

You could omit the troublesome line entirely if you did this:

system.db.runNamedQuery("CFG Queries/asrs_pallet_lookup1", {"lookLoc": self.view.params.LookupLoc})

Also, you aren’t capturing the named query result (return value from runNamedQuery). You would normally assign that (dataset) to some property.

If props.data on ASRSlookLoc is bound to that same named query, then you only need the refresh.

Thanks, i will definitely try that code in the script. It looks much easier. I am learning so I don’t always know better ways.

To give you an idea here is what I am trying to do.

In the pic, item 1, is bin location. This location has parameters that pull in off of a tag. This is an embedded view with multiple bin locations.

So when a team member clicks the location, I want the pallet information from the (“CFG Queries/asrs_pallet_lookup1”) to execute in the table that has the asterisk on it.

Would it be easier to create a tag and then somehow reference the tag to get the pallet information?

I really need this value to populate when i bind the table to the query.

My issue is that there like 200 binlocations

Hello Folks,

I encountered this error that appears to be quite common (A search on the forum yields several results), however none of the other threads seem to address this particular case.

The problem is already fixed (though I changed nothing), but since I have no idea what went wrong I thought I'd ask in case it happens again.

Here goes:
I have a gateway event scheduled script that sends out a daily summary of alarms.
All of the code is in a project script, all that's in the gateway script itself is this:

def onScheduledEvent():
	logger = system.util.getLogger("alarmSummaryScript")

	try:
#		AlarmSummary.summary.send_summary(site="foo", test=True)
		AlarmSummary.summary.send_summary(site="foo", customer="bar")
	except BaseException as e:
		logger.error(repr(e))

And here's the error:

NameError("global name 'AlarmSummary' is not defined",)

Now, I have 5 sites using this, never had any issue with it, and only ONE of those started misbehaving 2 weeks ago (I just came back from holidays).
All I did was use the test call that's commented in the snippet above, which makes it send the mail to me instead of the customers. It worked, so I put back the original line, and it also worked. Nothing changed.

Now, nothing changed on this site's project the day it stopped working, BUT I am in the process of reworking/refactoring everything into a global project from which all our sites could inherit, and on that very day I did create a child of this base project, using the same site as my guinea pig. While I can't see how it could affect another project's code (which don't inherit from the new global project), that's the only thing that happened around the time the issue arose.

This is all using perspective, version 8.1.18.
I'd very much like to avoid this happening again, especially when I'm out of the office for two weeks :X

Thanks for any clue you may have !

Gateway event scripts have a legacy scoping mode for python that has weird side-effects sometimes. Move even that little bit of code into a project script, so the gateway event itself can have a one-liner that just calls that.

Well it’s the call to the project script that was raising the error :confused:
I mean, the rest of the code was just there to determine that the error came from the event script itself, there’s no point in moving this, I might as well just remove it (all the error handling is done in the project script).