# Object.SetRoles Script Session Events

**URL:** <https://forum.inductiveautomation.com/t/object-setroles-script-session-events/70613>\
**Category:** Ignition\
**Tags:** perspective, vision\
**Created:** [March 3, 2023, 11:59pm UTC](https://forum.inductiveautomation.com/t/object-setroles-script-session-events/70613 "2023-03-03T23:59:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![splata](https://avatars.discourse-cdn.com/v4/letter/s/3bc359/32.png) [@splata](https://forum.inductiveautomation.com/u/splata)\
**Post date:** [March 3, 2023, 11:59pm UTC](https://forum.inductiveautomation.com/t/object-setroles-script-session-events/70613/1 "2023-03-03T23:59:09Z")

</div>

Hello

I made an script follow the manual to set an specific role if the user is found with a Named Query , in my frist test i put the script in a "Page Startup Session Events" and works perfectly.

then i decide to migrate to the real application in an "startup Session Events" , the same script fails , my first idea it was the scope of the system functions but reading the info they have the same scopes "gateway,vision client and prespective session".  
my second idea it was that in this moment of the session this script cant works until the app load the first page.  
the third idea i writed on the second argument of the user.getUser a fixed usern name

here is the fragment of the code that supposed to work.

```auto
		userToChange = system.user.getUser("Test",self.session.props.auth.user.userName)
		role=["Agendado"]
		userToChange.setRoles(role)
		system.user.editUser("Test",userToChange)

```

i check some topics related whit this error and is there one without answer with the same error.

 ![imagen](https://us1.discourse-cdn.com/inductiveautomation/original/3X/1/6/16c8f57f33fbb0b97a6fbbea70eeeaaa9b8ccb65.png)

 ![imagen](https://us1.discourse-cdn.com/inductiveautomation/original/3X/3/a/3ace431575db85303d7b0286e6a4899822947065.png)

in this case the script works only on PageStartup . what you think?

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [March 4, 2023, 12:46am UTC](https://forum.inductiveautomation.com/t/object-setroles-script-session-events/70613/2 "2023-03-04T00:46:12Z")

</div>

NoneType has no attribute "setRoles" indicates that "userToChange" is null when your code is executing. That indicates your script is failing to find your user. Figure out why.
