VaranAwesomenow
Mega Sage

Use case : Itil role is needed to update a CI, it application owners who dont have itil access can only read a CI, this script helps find out which it application owner has itil role and which ones dont.

var sLog = '';
var itOwner = [];
var outputArray = [];
var grBa = new GlideRecord('cmdb_ci_business_app');
grBa.query();
while(grBa.next()) {
itOwner.push(grBa.it_application_owner.sys_id);
}

for (var k = 0; k<itOwner.length; k++) {
var role = 'NoRole';
role = checkItil(itOwner[k]);
outputArray.push(itOwner[k] + "|" + role);
}

for(var m=0; m<outputArray.length; m++) {
sLog +=outputArray[m] + "\n";
}
gs.print(sLog);

function checkItil(sysId) {
var role = 'NoRole';
var grRole = new GlideRecord('sys_user_has_role');
grRole.addEncodedQuery('role.nameSTARTSWITHitil^user=' + sysId);
grRole.query();
if(grRole.next()) {
role = 'HasRole';
}
return role;
}

Version history
Last update:
‎12-08-2020 08:09 AM
Updated by: