SQL dataset returned not working in tag script

I have a script which works fine in the script console but is failing when I run it as a tag script. The point of failure is definitely in the way the script is looking at the SQL query return - by injecting flags into the script I can tell it is choking on the row “for row in range(query.getRowCount()):”. Playing with this I can see that ANY calls to pull data from the returned query are not working.

Again, I am able to run this script just fine from the script console so this is really a mystery to me. Can anyone please comment on this? Thanks!

email=‘Here is the list of problem shelf items for today:’ + ‘\r\n’ + ‘\r\n’
query = system.db.runNamedQuery(“Today’s Problem Shelf Items”)
email += str(query)+ ‘\r\n’
for row in range(query.getRowCount()): <—Here is where script is stopping!
for col in range(query.getColumnCount()):
email+=str( query.getValueAt(row, col) )
email+=’ ’
recipients = [“richard.white@xxxx.com”]
system.net.sendEmail(“exsmtp.na.xxxx.cnb”, “AlarmNotification@xxxx.com”, “Multi-Line Email”, email, 0, recipients)

There is different syntax for running system.db.runNamedQuery in a gateway context - you’ll need to put the project name.

https://docs.inductiveautomation.com/display/DOC80/system.db.runNamedQuery

Thank you! Yes, this resolved my issue. I’ve learned my lesson and will make sure I am looking at the 8.x documentation first… Much appreciated!