- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-28-2017 07:32 AM
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.
Solved! Go to Solution.
- Labels:
-
Automated Test Framework
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-28-2017 07:39 AM
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!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-28-2017 07:39 AM
Hello Jimmie,
The below is a script that I use to impersonate a user and run a BR, maybe this can put you on the correct path:
session.onlineImpersonate("abel.tuter");
var current = GlideRecord('incident');
if (!gs.hasRole("itil")) {
var u = gs.getUserID();
var qc = current.addQuery("caller_id", u).addOrCondition("opened_by", u).addOrCondition("watch_list", "CONTAINS", u);
gs.print("query restricted to user: " + u);
}
current.query();
while (current.next()) {
gs.print(current.number);
}
session.onlineUnimpersonate();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-28-2017 07:41 AM
Another script that I used to test if my impersonation works is as below:
var og = gs.getSession().impersonate('5136503cc611227c0183e96598c4f706');
gs.print(gs.getUser().getFullName());
var gr1 = new GlideRecord('sn_customerservice_case');
gr1.addQuery('sys_id',b08cd51fdba83a007a4cbedffe96196d');
gr1.query();
if(gr1.next())
gs.print("Found it");
else
gs.print("Not Found");
gs.getSession().impersonate(og);
*** Script: Guest
*** Script: Not Found
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-07-2020 05:28 AM
I have tried all of them but its not working in my case.
My case: I am using this in a runscript of a workflow where I am trying to update one of the sctask of the request item with the impersonated user. But the update is happening with the user who raised the request. And if I update the request item, it is updated with impersonated user.
So the issue is when I am gliding the sctask that was already created and updating the record.
Is there something I am missing. PLease help.
I have tried gs.getSession().onlineImpersonate("<user_name>");,new GlideImpersonate().impersonate(your user id);etc
The impersonate log says it is sussesfull but still the update is not with impersonated user.