Error in the gateway script

#1

I am trying to write a gateway timer script but getting the following error:

AttributeError: ‘com.inductiveautomation.ignition.common.script.Imm’ object has no attribute ‘gui’

What can be the possible reasons for this type of error?

0 Likes

#2

The gateway runs as a service and therefore has no GUI. No windows or templates or components or any visuals at all.

1 Like

#3

I am reading and writing the tags in my script, inserting it into the database.

0 Likes

#4

can you post your script?

1 Like

#5

To expand on Phil a bit - you’re trying to a call a system.gui.* scripting function from the gateway scope - which doesn’t work. I’m not sure what you’re doing, exactly; which is why having your script would be the most useful.

The error should give you a line number, however - whatever you’re doing on that line will have to be changed to not use a system.gui function.

1 Like

#6

Something that has bit me in the past is piling lots of useful functions in just one shared or project script. If there are client/designer scope imports in such a script to support gui stuff, and you try to call a generic function in the same script from gateway scope, the import for the other functions will break the entire script.
Try to keep your script modules organized by the scope(s) you intend to use them in.

3 Likes

#7

Does this scope difference cause errors the other way around?:

I’m calling system.db.runQuery from a button event handler script
this query is a stored procedure I AM HAVINGtrouble getting to execute, more to the point is that when the button is pushed, the result of the stored procedure (inserts 1 row into mysql table) is not observed until roughly a minute later.
AttributeError: ‘com.inductiveautomation.ignition.designer.gui.tool’ object has no attribute 'RunQuery

0 Likes

#8

Without the complete script and error, it is tough to be certain, but the capital ‘R’ is suspicious. Case matters.

0 Likes

#9

Case matters indeed, that turned out to be the issue, although the script seems to execute some time after event fires. Really want to get the stored procedure to be run at login and be run as close to button press time as possible…Event handler script:

username = event.source.parent.getComponent('USN').text
print username



userIP = str(system.net.getIpAddress())

print("\n  *\n  *\n  *\n User IP was: ", userIP)

password = event.source.parent.getComponent('Password Field').text
print password
print("\n  *\n  *\n  *\n Validating user credentials")
success= system.security.switchUser(username,password,event)
print("\n  *\n  *\n  *\n fetching user roles.")	
roles = system.security.getUserRoles(username, password)
strmessage = ''

# Log the user's name and IP address for possible future troubleshooting.
if success:
	strMessage = str("\n\n  User [%s] successfully authenticated in from [%s] " % (username, userIP))
	print("\n  *\n  *\n  *\n Success: ", strMessage)
else:
	strMessage = str("\n\n  User [%s] failed to  authenticate from [%s] " % (username, userIP))
	print("\n  *\n  *\n  *\n No Success", strMessage)
	
	print("\n\n  ", strMessage)
	print(roles)
		


	if success and ("Controls User" in roles) and (userIPAddress.find("192.168.100.*") > 0):
		
		strSql = str('call log_message("%s")' % strMessage)
		print("\n\n $$  \n\n  ##\n\n  ^^\n\n  *\n\n  *\n\n **\n\n using SLQ stmt ", strSql)
		system.db.runQuery(strSql)
0 Likes

#10

Please put triple back-quotes on lines by themselves above and below your code so we can read it. Like so:

```
Your code here
```

Edit your comment to include these, no need to repost.

0 Likes

#11

I bet that’s the actual source of the slowdown, not the query. Try using system.tag.read("[System]Client/IPAddress").value - the call to getIpAddress() is issuing a call out to a Java method that has to run native code to determine the actual IP address, and doesn’t cache.

0 Likes

#12

Your final “if success” block is indented such that it is part of the else clause of the “if success” block above it. I have no idea how that runQuery is ever called.

0 Likes

#13

Along with what both Paul and Phil said, print statements will slow down any scripting as well.

1 Like