Adding the users role based on what form they have submitted

I am using this code to add new users…

# Get new user
	userToGet = system.user.getNewUser("Users", self.getSibling("txtUsername").props.text)
		# Add some contact info
	userToGet.set("firstname", self.getSibling("txtFirstName").props.text)
	userToGet.set("lastname", self.getSibling("txtSecondName").props.text)
	contactInfo = {"email":self.getSibling("txtEmailAddress").props.text}
	userToGet.set("password", self.getSibling("txtPassword").props.text)
		# Adds a user to the the usersource.
	system.user.addUser("Users", userToGet)

I have tried to set the users roles by trying to copy the way I have the first name and second name done but it isnt working. How would I be able to set user role to administrator in this bit of code?

After speaking with @PGriffith:

roles = ['RoleOne', 'RoleTwo']
system.user.addUser("Users", userToGet)
1 Like

That worked thanks.

1 Like

Hi, I am trying to use the same idea for letting users update their account details and I am getting the following error…

Error running action ‘component.onActionPerformed’ on UpdateAccount@D/root/btnChange: Traceback (most recent call last): File " ", line 22, in runAction AttributeError: ‘NoneType’ object has no attribute ‘set’

This is the code I am using…

userToChange = system.user.getUser("Users", self.session.props.auth.user.userName)

	userToChange.set("firstname", self.getSibling("txtFirstName").props.text)
	userToChange.set("lastname", self.getSibling("txtSecondName").props.text)
	userToChange.set("password", self.getSibling("txtPassword").props.text)
	userToChange.set("username", self.getSibling("txtUsername").props.text)

	system.user.editUser("Users", userToChange)

I believe it was working before and has just recently stopped.

  1. Which of those lines is line 22? I want to assume userToChange.set("firstname", self.getSibling("t… but verification is the first step.
  2. While we always prefer formatted code like you’ve done here, indentation is incredibly important in Jython, and the difference in indentation concerns me. Could you add a screenshot of the code area in question so that I can verify the indentation is not the problem in some way?
  3. This is not the way to “update” users which already exist - you should use system.user.editUser for that.


Am I not using this example the right way?

userToChange = system.user.getUser("default", self.session.props.auth.user.userName)

Is “Users” a good user source? You have it configured?

Yes, I am using it for adding new users and that is working fine

Does the user already exist in the user source?

Yes, I am taking the users details from the session and displaying them in textboxs to be edited and submitted through a button.

You might need to contact support because I’m not seeing anything that would cause this based on your responses.

I have contacted support and I am waiting on a response. This is the error in my logs…

com.inductiveautomation.ignition.common.script.JythonExecException: Traceback (most recent call last): File “”, line 22, in runAction AttributeError: ‘NoneType’ object has no attribute ‘set’

at org.python.core.Py.AttributeError(

at org.python.core.PyObject.noAttributeError(

at org.python.core.PyObject.getattr(

at org.python.pycode._pyx1217.runAction$1(:40)

at org.python.pycode._pyx1217.call_function()



at org.python.core.PyFunction.function___call__(



at com.inductiveautomation.ignition.common.script.ScriptManager.runFunction(

at com.inductiveautomation.ignition.common.script.ScriptManager.runFunction(

at com.inductiveautomation.ignition.gateway.project.ProjectScriptLifecycle$TrackingProjectScriptManager.runFunction(

at com.inductiveautomation.ignition.common.script.ScriptManager$ScriptFunctionImpl.invoke(

at com.inductiveautomation.ignition.gateway.project.ProjectScriptLifecycle$AutoRecompilingScriptFunction.invoke(

at com.inductiveautomation.perspective.gateway.script.ScriptFunctionHelper.invoke(

at com.inductiveautomation.perspective.gateway.action.ScriptAction.runAction(

at com.inductiveautomation.perspective.gateway.model.ActionCollection$ActionSequence$ExecuteActionsTask.lambda$call$0(

at com.inductiveautomation.perspective.gateway.api.LoggingContext.mdc(

at com.inductiveautomation.perspective.gateway.model.ActionCollection$ActionSequence$

at com.inductiveautomation.perspective.gateway.model.ActionCollection$ActionSequence$

at com.inductiveautomation.perspective.gateway.threading.BlockingTaskQueue$

at java.base/java.util.concurrent.Executors$ Source)

at java.base/ Source)

at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)

at java.base/java.util.concurrent.ThreadPoolExecutor$ Source)

at java.base/ Source)

Caused by: org.python.core.PyException: Traceback (most recent call last): File “”, line 22, in runAction AttributeError: ‘NoneType’ object has no attribute ‘set’

… 27 common frames omitted

Seems pretty clear that userToChange is null. Meaning, your user lookup didn’t return a user for some reason. You have to deal with that case.


@pturmel is correct. Based on your responses, however, I’m not able to tell you why no user is being returned. If you are already waiting on support, you should hang tight and wait.

1 Like