Object.SetRoles Script Session Events

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.

		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.

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

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.