ATF question re: drawing information from a record query to use as reference in a second query

Josh_
Tera Contributor

I am trying to write an ATF test that should be simple, but has one sticking point right at the beginning.

 

I need to impersonate a member of a specific group.  Best practices say that we should not directly impersonate an existing user, so I have two choices: create one of my own, or try to path my way into impersonating someone in the org who is a member of that group, but whose identity is not fixed.

 

I query sys_user_grmember to find a user in that group, which is fine.

 

But the record is a Group Member record, rather than a User record.  There is no way to dot walk my impersonation step to the User field in the Group Member record.  I have tried other, similar paths, but cannot find a way to do it.  I'm sure there is scripting that could do it, but I am unclear as to what would work.

 

If anyone has an idea as to how this might progress, without creating a new user and assigning all roles and groups, I would appreciate it.

 

1.  Record query on sys_user_grmember for [group name] and email > is not empty (empty emails are system integration accounts for us).  Current query finds 41 group members.

2.  Would like to impersonate someone from step 1.  But cannot dot walk at all beyond the record ID itself; if I could get to Group Member.User, this is a simple job.

 

Please advise?

1 ACCEPTED SOLUTION

Chidanand_VK
Tera Expert

Hi @Josh_ ,

Use the below script in the 'Run Server Side Script' step and in the Impersonation test step select this (Run Server Side Script test step) using data pill picker.

 

var group = new GlideRecord("sys_user_group");
group.get('11f6346787ad4990db63ece60cbb35ba'); //SYS ID of the Group

var groupMember = new GlideRecord("sys_user_grmember");
groupMember.addEncodedQuery('group=' + group.sys_id + '^user.emailISNOTEMPTY'); //Adding a query of User.Email is NOT Empty
groupMember.query();

while(groupMember.next()) {
    var userSysId = groupMember.user.sys_id;
    outputs.record_id = userSysId; //Getting Output of this Run Server Side Script test step as the User record
}

View solution in original post

6 REPLIES 6

Chidanand_VK
Tera Expert

Hi @Josh_ ,

Use the below script in the 'Run Server Side Script' step and in the Impersonation test step select this (Run Server Side Script test step) using data pill picker.

 

var group = new GlideRecord("sys_user_group");
group.get('11f6346787ad4990db63ece60cbb35ba'); //SYS ID of the Group

var groupMember = new GlideRecord("sys_user_grmember");
groupMember.addEncodedQuery('group=' + group.sys_id + '^user.emailISNOTEMPTY'); //Adding a query of User.Email is NOT Empty
groupMember.query();

while(groupMember.next()) {
    var userSysId = groupMember.user.sys_id;
    outputs.record_id = userSysId; //Getting Output of this Run Server Side Script test step as the User record
}

This did it, thank you.

 

Pasting it in blew the syntax, but I got it reset and the test flows properly.  I appreciate the assistance.

Thanks!! for accepting my answer as a Solution. 🙂

 

Please mark the Solution as Helpful, if it really helped.

Shaqeel
Mega Sage

Hi @Josh_ 

 

Have you tied create a user step and adding the group in this step only using direct method or using dot walk?

Shaqeel_0-1736507312556.png

 

Regards

Shaqeel

 


***********************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting "Accept as Solution" and " Helpful." This action benefits both the community and me.

***********************************************************************************************************************





Regards

Shaqeel