Impersonating users through script

JimmieOdelius
Tera Expert

Hi.


I'm setting up tests in the Automated Test Framework and I ran into trouble when I stumbled upon the need to impersonate users via script.

I found somewhere else on the community that I could use

session.setUser("username");

This did not work however and resulted in an error message like "Attempted script access to inaccessible member denied." which my google-fu failed to find anything about.

Has anyone done anything like this before? Please help.

Thanks in advance.

1 ACCEPTED SOLUTION

Brandon Smith3
Kilo Expert

Jimmie,



I've had little luck with impersonations, however I have used gs.getSession().impersonate('xxx') within an ajax script include. Give it a try, hope it helps!


View solution in original post

7 REPLIES 7

Brandon Smith3
Kilo Expert

Jimmie,



I've had little luck with impersonations, however I have used gs.getSession().impersonate('xxx') within an ajax script include. Give it a try, hope it helps!


Hi Brandon.



Thank you for your response.


This was the correct solution.



Apparently



gs.getSession().impersonate("usernameORsysid")



takes both sysid and username as input.


Can you provide me with complete script. This seems to give me a null string.


corina
ServiceNow Employee
ServiceNow Employee

Hello Jimmie



var origUser = gs.getSession().impersonate('sys_id' );