I am having a strange situation where i get the following error when trying to run a named query via a Gateway scoped shared script:
Traceback (most recent call last):
File "<module:shared.util>", line 190, in wrapper
File "<module:shared.util>", line 492, in getMCcurrDataFromSQL
Exception: java.lang.Exception: Did not find query GetMCStats in project resources.
I am currently using the following method to determine the scope of which the function is being called, which seemed to work just fine for me in versions 7.9.X, but i am not sure it is the best way to do it now in versions 8.1.X.
The getScope function i am using:
def getScope():
"""
Determines what scope code is being called from. Certain functions require different parameters depending
on scope.
Returns:
location (int): 0=Gateway, 1=Client, 2=Designer
Date: Author: Notes:
26/11/2019 richardNZ15 Initial
"""
from com.inductiveautomation.ignition.common.model import ApplicationScope
scope = ApplicationScope.getGlobalScope()
if ApplicationScope.isClient(scope):
location = 1
elif ApplicationScope.isDesigner(scope):
location = 2
elif ApplicationScope.isGateway(scope):
location = 0
else:
location = 0
# end if
return location
# end def
The function referenced in the error message that i am trying to run:
@errorHandlerGlobal("MachineCenters","shared/util/getMCcurrDataFromSQL ",alarmRqd=False)
def getMCcurrDataFromSQL(MC_ID):
"""
This function utilises a named query (GetMCStats) to return the current run minutes and production volume for a
machine center specified by unique ID (MC_ID).
Parameters:
MC_ID (string): Machine center unique ID
Returns:
runMin (int): Current accumulated MC run minutes
prodVol (float): Current accumulated MC production volume
Date: Author: Revision:
17/02/2022 richardNZ15 Initial
"""
scriptName = "shared/util/getMCcurrDataFromSQL"
logger = system.util.getLogger("MachineCenters")
runMin = -1
prodVol = -1.0
params = {"MC_ID":MC_ID}
# Need to specify Project name as first argument if calling from Gateway scope.. otherwise must be left blank.
if shared.util.getScope() > 0:
data = system.db.runNamedQuery("GetMCStats", params)
else:
data = system.db.runNamedQuery("G1-Line01","GetMCStats", params)
# end if
if data.getRowCount() != 1:
logger.error(scriptName + " - Invalid number of rows returned from Named Query 'GetMCStats' for MC_ID = '%s'" % MC_ID)
return runMin, prodVol
else:
runMin = data.getValueAt(0,"CurrRunMins")
prodVol = data.getValueAt(0,"CurrM3")
###logger.debug(scriptName + " - Stats for MC '%s': runMin= %0d, prodVol= %06f" % (MC_ID, runMin, prodVol))
print (scriptName + " - Stats for MC '%s': runMin= %0d, prodVol= %06f" % (MC_ID, runMin, prodVol))
return runMin, prodVol
# end if
# end def
I currently have the following project inheritance configured, which i suspect has something to do with the issues:
G1-Master
G1-Master > G1-Line01
G1-Master > G1-Backend
I would expect all normal calls of the function to originate from G1-Line01 project, which is the main SCADA project.
I get the error while calling the function in the G1-Master Designer scope, in the script console, but do not get any errors while calling from G1-Line01 Designer scope
The named query itself is defined in the G1-Line01 project, so it makes sense that i would get errors in the G1-Master designer.
What is odd is that i’ve got errors when users have called the function in the G1-Line01 project. Is this because the script call is calling shared.util.getMCcurrDataFromSQL
, which is a gateway shared script defined in the G1-Master project?
In which case i’m doomed?
Would it not be simpler if IA just allowed us to pass the ProjectName into the system.db.runNamedQuery
function regardless of scope?? So we can point it where it needs to go?