create a fix script to add evt_mgmt_operator role to itil , getting errors

ServNowDev
Tera Guru

 

 

addRoletoRole();

function addRoletoRole(){
    // Find the ITIL role
    var itilRole = new GlideRecord('sys_user_role');
    itilRole.addQuery('name', 'ITIL');
    itilRole.query();

    if (itilRole.next()) {
        // Check if the evt_mgmt_operator role already exists in ITIL role
        var itilRoles = itilRole.getValue('roles');
        if (itilRoles.indexOf('evt_mgmt_operator') === -1) {
            // Add evt_mgmt_operator role to the ITIL role
            var newRoles = itilRoles + ',evt_mgmt_operator';
            itilRole.setValue('roles', newRoles);
            itilRole.update();
            gs.info('evt_mgmt_operator role added to ITIL role successfully.');
        } else {
            gs.info('evt_mgmt_operator role already exists in ITIL role.');
        }
    } else {
        gs.error('ITIL role not found.');
    }
}

 

getting error below:

 

Evaluator: com.glide.script.RhinoEcmaError: Cannot convert null to an object.
   script : Line(12) column(0)
      9:     if (itilRole.next()) {
     10:         // Check if the evt_mgmt_operator role already exists in ITIL role
     11:         var itilRoles = itilRole.getValue('roles');
==>  12:         if (itilRoles.indexOf('evt_mgmt_operator') === -1) {
     13:             // Add evt_mgmt_operator role to the ITIL role
     14:             var newRoles = itilRoles + ',evt_mgmt_operator';
     15:             itilRole.setValue('roles', newRoles);

[0:00:00.022] Total Time
1 ACCEPTED SOLUTION

Explanation:

evt_mgmt_operator contains evt_mgmt_user role

evt_mgmt_user contains sam_core_user role

sam_core_user contains itil role

 

So itil is already contained inside evt_mgmt_operator

 

View solution in original post

13 REPLIES 13

unfortunately ive suggested but this is so far what they want to accomplish role to role, no role to groups or custom role to role , itil users need the evt_mgmt_operator role and its not allowing me to add

Hi @ServNowDev 

 

I got the Root cause why you are not able to add evt_mgmt_operator to itil role

The evt_mgmt_operator role contains itil role already indirectly.

That is why you would be getting the cyclicity error

 

Explanation:

evt_mgmt_operator contains evt_mgmt_user role

evt_mgmt_user contains sam_core_user role

sam_core_user contains itil role

 

So itil is already contained inside evt_mgmt_operator

 

Awesome, thanks so much didnt catch that , simple remove of sam_core_user fixed my issue it now attaches thanks a ton!!