# Adding the users role based on what form they have submitted

**URL:** <https://forum.inductiveautomation.com/t/adding-the-users-role-based-on-what-form-they-have-submitted/43147>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [February 8, 2021, 7:59pm UTC](https://forum.inductiveautomation.com/t/adding-the-users-role-based-on-what-form-they-have-submitted/43147 "2021-02-08T19:59:34Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![seanbuckley2698](https://avatars.discourse-cdn.com/v4/letter/s/d6d6ee/32.png) [@seanbuckley2698](https://forum.inductiveautomation.com/u/seanbuckley2698)\
**Post date:** [February 8, 2021, 7:59pm UTC](https://forum.inductiveautomation.com/t/adding-the-users-role-based-on-what-form-they-have-submitted/43147/1 "2021-02-08T19:59:34Z")

</div>

Hi,  
I am using this code to add new users…

```auto
# 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.addContactInfo(contactInfo)
	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?

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [February 8, 2021, 8:21pm UTC](https://forum.inductiveautomation.com/t/adding-the-users-role-based-on-what-form-they-have-submitted/43147/2 "2021-02-08T20:21:49Z")

</div>

After speaking with @paul-griffith:

```auto
roles = ['RoleOne', 'RoleTwo']
userToGet.setRoles(roles)
system.user.addUser("Users", userToGet)

```

---

<div class="post-metadata">

**Author:** ![seanbuckley2698](https://avatars.discourse-cdn.com/v4/letter/s/d6d6ee/32.png) [@seanbuckley2698](https://forum.inductiveautomation.com/u/seanbuckley2698)\
**Post date:** [February 8, 2021, 8:58pm UTC](https://forum.inductiveautomation.com/t/adding-the-users-role-based-on-what-form-they-have-submitted/43147/3 "2021-02-08T20:58:15Z")

</div>

> [@cmallonee](#):
>
> roles = ['RoleOne', 'RoleTwo'] userToGet.setRoles(roles)

That worked thanks.

---

<div class="post-metadata">

**Author:** ![seanbuckley2698](https://avatars.discourse-cdn.com/v4/letter/s/d6d6ee/32.png) [@seanbuckley2698](https://forum.inductiveautomation.com/u/seanbuckley2698)\
**Post date:** [March 18, 2021, 2:17pm UTC](https://forum.inductiveautomation.com/t/adding-the-users-role-based-on-what-form-they-have-submitted/43147/4 "2021-03-18T14:17:25Z")

</div>

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…

```auto
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.

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [March 18, 2021, 3:12pm UTC](https://forum.inductiveautomation.com/t/adding-the-users-role-based-on-what-form-they-have-submitted/43147/5 "2021-03-18T15:12:20Z")

</div>

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](https://docs.inductiveautomation.com/display/DOC81/system.user.editUser) for that.

---

<div class="post-metadata">

**Author:** ![seanbuckley2698](https://avatars.discourse-cdn.com/v4/letter/s/d6d6ee/32.png) [@seanbuckley2698](https://forum.inductiveautomation.com/u/seanbuckley2698)\
**Post date:** [March 18, 2021, 3:18pm UTC](https://forum.inductiveautomation.com/t/adding-the-users-role-based-on-what-form-they-have-submitted/43147/6 "2021-03-18T15:18:08Z")

</div>

![code](https://us1.discourse-cdn.com/inductiveautomation/original/3X/2/9/2933dfb90a0adef2bbcd679317689fa49f4f0a34.png)

---

<div class="post-metadata">

**Author:** ![seanbuckley2698](https://avatars.discourse-cdn.com/v4/letter/s/d6d6ee/32.png) [@seanbuckley2698](https://forum.inductiveautomation.com/u/seanbuckley2698)\
**Post date:** [March 18, 2021, 6:17pm UTC](https://forum.inductiveautomation.com/t/adding-the-users-role-based-on-what-form-they-have-submitted/43147/7 "2021-03-18T18:17:04Z")

</div>

Am I not using this example the right way?

---

<div class="post-metadata">

**Author:** ![wking](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/wking/32/21823_2.png) [@wking](https://forum.inductiveautomation.com/u/wking)\
**Post date:** [March 18, 2021, 6:43pm UTC](https://forum.inductiveautomation.com/t/adding-the-users-role-based-on-what-form-they-have-submitted/43147/8 "2021-03-18T18:43:17Z")

</div>

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

```

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

---

<div class="post-metadata">

**Author:** ![seanbuckley2698](https://avatars.discourse-cdn.com/v4/letter/s/d6d6ee/32.png) [@seanbuckley2698](https://forum.inductiveautomation.com/u/seanbuckley2698)\
**Post date:** [March 18, 2021, 8:31pm UTC](https://forum.inductiveautomation.com/t/adding-the-users-role-based-on-what-form-they-have-submitted/43147/9 "2021-03-18T20:31:02Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [March 19, 2021, 1:01am UTC](https://forum.inductiveautomation.com/t/adding-the-users-role-based-on-what-form-they-have-submitted/43147/10 "2021-03-19T01:01:55Z")

</div>

Does the user already exist in the user source?

---

<div class="post-metadata">

**Author:** ![seanbuckley2698](https://avatars.discourse-cdn.com/v4/letter/s/d6d6ee/32.png) [@seanbuckley2698](https://forum.inductiveautomation.com/u/seanbuckley2698)\
**Post date:** [March 19, 2021, 12:45pm UTC](https://forum.inductiveautomation.com/t/adding-the-users-role-based-on-what-form-they-have-submitted/43147/11 "2021-03-19T12:45:10Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [March 19, 2021, 2:25pm UTC](https://forum.inductiveautomation.com/t/adding-the-users-role-based-on-what-form-they-have-submitted/43147/12 "2021-03-19T14:25:05Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![seanbuckley2698](https://avatars.discourse-cdn.com/v4/letter/s/d6d6ee/32.png) [@seanbuckley2698](https://forum.inductiveautomation.com/u/seanbuckley2698)\
**Post date:** [March 21, 2021, 10:36am UTC](https://forum.inductiveautomation.com/t/adding-the-users-role-based-on-what-form-they-have-submitted/43147/13 "2021-03-21T10:36:26Z")

</div>

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(Py.java:207)

at org.python.core.PyObject.noAttributeError(PyObject.java:1032)

at org.python.core.PyObject. **getattr** (PyObject.java:1027)

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

at org.python.pycode.\_pyx1217.call\_function()

at org.python.core.PyTableCode.call(PyTableCode.java:171)

at org.python.core.PyBaseCode.call(PyBaseCode.java:308)

at org.python.core.PyFunction.function\_\_\_call\_\_(PyFunction.java:471)

at org.python.core.PyFunction. **call** (PyFunction.java:466)

at org.python.core.PyFunction. **call** (PyFunction.java:461)

at com.inductiveautomation.ignition.common.script.ScriptManager.runFunction(ScriptManager.java:822)

at com.inductiveautomation.ignition.common.script.ScriptManager.runFunction(ScriptManager.java:806)

at com.inductiveautomation.ignition.gateway.project.ProjectScriptLifecycle$TrackingProjectScriptManager.runFunction(ProjectScriptLifecycle.java:687)

at com.inductiveautomation.ignition.common.script.ScriptManager$ScriptFunctionImpl.invoke(ScriptManager.java:965)

at com.inductiveautomation.ignition.gateway.project.ProjectScriptLifecycle$AutoRecompilingScriptFunction.invoke(ProjectScriptLifecycle.java:752)

at com.inductiveautomation.perspective.gateway.script.ScriptFunctionHelper.invoke(ScriptFunctionHelper.java:101)

at com.inductiveautomation.perspective.gateway.action.ScriptAction.runAction(ScriptAction.java:71)

at com.inductiveautomation.perspective.gateway.model.ActionCollection$ActionSequence$ExecuteActionsTask.lambda$call$0(ActionCollection.java:263)

at com.inductiveautomation.perspective.gateway.api.LoggingContext.mdc(LoggingContext.java:54)

at com.inductiveautomation.perspective.gateway.model.ActionCollection$ActionSequence$ExecuteActionsTask.call(ActionCollection.java:252)

at com.inductiveautomation.perspective.gateway.model.ActionCollection$ActionSequence$ExecuteActionsTask.call(ActionCollection.java:221)

at com.inductiveautomation.perspective.gateway.threading.BlockingTaskQueue$TaskWrapper.run(BlockingTaskQueue.java:154)

at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)

at java.base/java.util.concurrent.FutureTask.run(Unknown Source)

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

at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)

at java.base/java.lang.Thread.run(Unknown 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

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [March 21, 2021, 12:01pm UTC](https://forum.inductiveautomation.com/t/adding-the-users-role-based-on-what-form-they-have-submitted/43147/14 "2021-03-21T12:01:54Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [March 21, 2021, 3:29pm UTC](https://forum.inductiveautomation.com/t/adding-the-users-role-based-on-what-form-they-have-submitted/43147/15 "2021-03-21T15:29:52Z")

</div>

@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.
