System.gui.inputbox has no attribute 'text'

I am running 7.9.18 and have a button that I want to run a system.gui.inputbox in the script.

When I try I get the following error

Traceback (most recent call last):
  File "<event:mousePressed>", line 3, in <module>
AttributeError: 'com.inductiveautomation.factorypmi.application.com' object has no attribute 'text'

	at org.python.core.Py.AttributeError(Py.java:173)
	at org.python.core.PyObject.noAttributeError(PyObject.java:930)
	at org.python.core.PyObject.object___getattribute__(PyObject.java:3692)
	at org.python.core.PyObject$object___getattribute___exposer.__call__(Unknown Source)
	at org.python.core.Deriveds.__findattr_ex__(Deriveds.java:59)
	at org.python.core.PyObjectDerived.__findattr_ex__(PyObjectDerived.java:983)
	at com.inductiveautomation.factorypmi.application.script.PyComponentWrapper.__findattr_ex__(PyComponentWrapper.java:131)
	at org.python.core.PyObject.__getattr__(PyObject.java:923)
	at org.python.pycode._pyx80.f$0(<event:mousePressed>:5)
	at org.python.pycode._pyx80.call_function(<event:mousePressed>)
	at org.python.core.PyTableCode.call(PyTableCode.java:165)
	at org.python.core.PyCode.call(PyCode.java:18)
	at org.python.core.Py.runCode(Py.java:1275)
	at com.inductiveautomation.ignition.common.script.ScriptManager.runCode(ScriptManager.java:636)
	at com.inductiveautomation.factorypmi.application.binding.action.ActionAdapter.runActions(ActionAdapter.java:193)
	at com.inductiveautomation.factorypmi.application.binding.action.ActionAdapter.invoke(ActionAdapter.java:284)
	at com.inductiveautomation.factorypmi.application.binding.action.RelayInvocationHandler.invoke(RelayInvocationHandler.java:57)
	at com.sun.proxy.$Proxy41.mousePressed(Unknown Source)
	at java.desktop/java.awt.Component.processMouseEvent(Unknown Source)
	at java.desktop/javax.swing.JComponent.processMouseEvent(Unknown Source)
	at java.desktop/java.awt.Component.processEvent(Unknown Source)
	at java.desktop/java.awt.Container.processEvent(Unknown Source)
	at java.desktop/java.awt.Component.dispatchEventImpl(Unknown Source)
	at java.desktop/java.awt.Container.dispatchEventImpl(Unknown Source)
	at java.desktop/java.awt.Component.dispatchEvent(Unknown Source)
	at java.desktop/java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
	at java.desktop/java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
	at java.desktop/java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
	at java.desktop/java.awt.Container.dispatchEventImpl(Unknown Source)
	at java.desktop/java.awt.Window.dispatchEventImpl(Unknown Source)
	at java.desktop/java.awt.Component.dispatchEvent(Unknown Source)
	at java.desktop/java.awt.EventQueue.dispatchEventImpl(Unknown Source)
	at java.desktop/java.awt.EventQueue.access$500(Unknown Source)
	at java.desktop/java.awt.EventQueue$3.run(Unknown Source)
	at java.desktop/java.awt.EventQueue$3.run(Unknown Source)
	at java.base/java.security.AccessController.doPrivileged(Native Method)
	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
	at java.desktop/java.awt.EventQueue$4.run(Unknown Source)
	at java.desktop/java.awt.EventQueue$4.run(Unknown Source)
	at java.base/java.security.AccessController.doPrivileged(Native Method)
	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
	at java.desktop/java.awt.EventQueue.dispatchEvent(Unknown Source)
	at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
	at java.desktop/java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.desktop/java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.desktop/java.awt.EventDispatchThread.run(Unknown Source)

Ignition v7.9.18 (b2021062913)
Java: Azul Systems, Inc. 9.0.7.4

I am just trying right now with the off the shelf script from the help document

txt = system.gui.inputBox("Enter text:", event.source.text)
if txt != None:
   event.source.text = txt

Try without the broken punctuation.

If you check the doc that second argument is just the default text -
image

I don't know where you are putting your script, but wherever it is, does not have a .text property. Just put your default text value directly in it.

Also to format code on the forum do it like so

```

txt  = system.gui.inputBox("Enter text:", event.source.text)
if txt !=None:
    event.source.text =txt

```

Three ticks to start, your code, then three ticks to finish.

My thought on using this is as follows.

  1. on a button push call the gui.inputbox to enter/scan a badge number
  2. use the input from the input to check in a database if the badge has the appropriate user level
  3. if they do open the appropriate screen if not error box.
temp = system.gui.inputBox("Enter text:", event.source.text)

if len(temp)  == 5:
	id = temp
	qu = "select role_id from [IgnitionDB].[dbo].[BadgeScan_user_rl]  rid "
	qu += "INNER JOIN [IgnitionDB].[dbo].[BadgeScan_users] bs_user on rid.user_id = bs_user.id "
	qu += "where bs_user.username = 'u%s'"%id
	try:
	    rst = system.db.runScalarQuery(qu,"IgnitionDB")
	except:
	    err += "%s\n"%traceback.format_exc()
	    
if rst >= 4:
	window = system.nav.openWindow('Adjust offset')
	system.nav.centerWindow(window)
else:
	errorMessage = "Maintenance user rights required."
	errorMessage += " You don't have proper security privileges."
	system.gui.errorBox(errorMessage)

Couple of things. the text property of a button is simply what you see on the button label, so I suggest you just change that line to
system.gui.inputBox("Enter text:", 'SOME HARDCODED DEFAULT HERE') or do an empty string if you don't want anything like ''.

Instead of getting your roles by querying the tables directly, use system.security.getRoles system.security.getRoles - Ignition User Manual 7.9 - Ignition Documentation - let the user source manage this for you and use the system.user api to get what you need. With this too, you don't need to enter anything presuming that a user is already logged in. However, if a user is not logged in you can do that too.

Assuming a user is not logged in and you are okay with logging them in here -

user = system.gui.inputBox("Username", "")
password = system.gui.passwordBox("Password", "")
# the next line will try to log the user in, returns True if user/pass worked false otehrwise
loggedIn = system.security.switchUser(user, password)
if loggedIn:
    roles = system.security.getRoles()
    # Now you can use the actual names of the roles instead of having to rely on the id
    if 'someRole' in roles:
        window = system.nav.openWindow('Adjust offset')
    	system.nav.centerWindow(window)
    else:
        errorMessage = "Maintenance user rights required.  You don't have proper security privileges."
	    system.gui.errorBox(errorMessage)

This is how I would do it. With Ignition, if there's any part that you have to configure in the gateway like a user source, odds are there is an API they provide for you to use so you don't have to run raw sql regarding it.

The way you're doing it the person only needs to know a username to get access which is not very secure.