Issue/Error while adding snc_external to snc_internal users using fix script

Dhanunjay Kumar
Giga Contributor

Hi Experts,

We have a requirement to replace snc_internal role with snc_external to existing users with employe type CU/Empty.

We have started implementing the requirement to just add snc_external role to existing users, but we are getting error, would require experts help in resolving the issue.

Background Script:

var gr = new GlideRecord("sys_user");
gr.addQuery('active', true);
gr.addEncodedQuery('u_employee_type=CU^ORu_employee_typeISEMPTY');
gr.addEncodedQuery('sys_idIN00076b09db160700047dd7795e961934,000143344776899485b05131e36d439d');
gr.query();
while (gr.next()) {
    var grd = new GlideRecord('sys_user_has_role');
    grd.addQuery('user',gr.sys_id);
    grd.addEncodedQuery('role=7fcaa702933002009c8579b4f47ffbde');
    grd.query();
if (grd.next()){
           gs.print('name = '+ grd.user.getDisplayValue());
        // grd.initialize();
        grd.user = gr.sys_id;
        grd.role = '940ba702933002009c8579b4f47ffbe2'; // sys_id of snc_external
       grd.insert();
//gs.print("total number of users matching query: "+grd.getRowCount());
    }
}

 

Error when we are adding snc_extenal to the user who already have snc_internal role

message: Operation interrupted: explicit role collision. User 'cXXXXX' has conflicting role 'snc_internal'. All explicit role collisions in hierarchy must be addressed. See documentation for more information
Operation interrupted: explicit role collision. User 'cXXXXX' has conflicting role 'snc_internal'. All explicit role collisions in hierarchy must be addressed. See documentation for more information: no thrown error
3 REPLIES 3

MrMuhammad
Giga Sage

Hi,

snc_internal and snc_external can't be assigned at the same time. So in the script as you are using insert() so its trying to add the snc_external role while the snc_internal is already assigned. so just replace insert() with update

please try below

var gr = new GlideRecord("sys_user");
gr.addQuery('active', true);
gr.addEncodedQuery('u_employee_type=CU^ORu_employee_typeISEMPTY');
gr.addEncodedQuery('sys_idIN00076b09db160700047dd7795e961934,000143344776899485b05131e36d439d');
gr.query();
while (gr.next()) {
    var grd = new GlideRecord('sys_user_has_role');
    grd.addQuery('user',gr.sys_id);
    grd.addEncodedQuery('role=7fcaa702933002009c8579b4f47ffbde');
    grd.query();
if (grd.next()){
           gs.print('name = '+ grd.user.getDisplayValue());
        // grd.initialize();
        grd.user = gr.sys_id;
        grd.role = '940ba702933002009c8579b4f47ffbe2'; // sys_id of snc_external
       grd.update();
//gs.print("total number of users matching query: "+grd.getRowCount());
    }
}
Regards,
Muhammad

@Dhanunjay Kumar Nakka 

Have you get a chance to try above code? If your issue has been resolved then please close the thread by accepting the solution.

Regards,

Muhammad

Regards,
Muhammad

Mahendra RC
Mega Sage

Hello Dhanunjay,

You have to first remove snc_internal role from all those user using a script and then assign snc_external role to the users. I believe you cannot assign snc_external role to the users who have snc_internal role.

Please mark this as helpful/correct, if it answer your question.

Thanks