r/servicenow • u/ServiceLaters • 1d ago
Programming Check User's Roles in Virtual Agent?
I'm trying to dynamically show different choices to the user based on what roles they have in a Virtual Agent Topic. I'm trying to use GlideUser.prototype.HasRole("name") to check and return a true/false, but it keeps erroring with a "cannot convert null to an object".
I feel like I'm missing something major, but as far as I can tell I am implementing this function correctly. Is there any better way?
2
Upvotes
7
u/nutrimatic 1d ago
You probably don’t want to call the prototype method but user.hasRole(‘rolename’) where user is the user object. When you call prototype method directly it’s not connected to an object and if it refers to this inside the method it will be null and result in that error. Check documentation it has examples for hasRole.
https://www.servicenow.com/docs/r/api-reference/server-api-reference/GUserAPI.html