Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Issue in target instance

Sarah Bouil
Tera Expert

Hi,

 

In production, the role 'u_aqcc_read' is having 3 members like: A,B,C, so they can have access ready only. In test, the same users A,B,C is having access to edit or write.

 

So when we clone from prod to test the role 'u_aqcc_read' is adding to users A,B,C in test, hence they are loosing the edit or write access.

 

So I want to clean the role 'u_aqcc_read' from users in test by using Cleanup scripts after post clone. How to do that?

7 REPLIES 7

Tony Chatfield1
Kilo Patron

Hi, exactly what you need to do will depend on whether the role is applied directly or via group membership.
If via a group then a glidequery on sys_user_grmember for the group and\or role
Then delete the results.
if via direct relationship to sys_user, a glidequery on sys_user_has_role for the role
Then delete the results.

 

 

var grm= new GlideRecord('sys_user_grmember');
grmaddQuery('group=3c679568db0ba8d0123dee0c4567890c^ORgroup=987f2a234ff3d23456ca3d828110c945');//group sys_id's
grmquery();
if(grmnext())
{
//grmdeleteRecord();
}

 

The above code is fine? or need to add any additional code.

Hi, small syntax error and also you are using an encoded query so

grm.addEncodedQuery('group=3c679568db0ba8d0123dee0c4567890c^ORgroup=987f2a234ff3d23456ca3d828110c945');//group sys_id's
But as per other post, I would look ats deleting the role from the group.

 

Edit, also missing . s
grm.query();
if(grm.next())
{
//grm.deleteRecord();
}

The read only role might be added to user from group also. So I have to identify the users and need to delete the read only role from that user in target instance.