script to trigger Event to remove disable user

BanuMahalakshmi
Tera Contributor

Hi,

 

we keep the business rule for when a user becomes deactivated, and instead of the business rule updating the CI's level 1 approver group
(to remove member), trigger an event passing the CI and the disabled user... and the event logic will update the level 1 approver field to remove disabled user.

 

 var userSysId = current.sys_id.toString();
    var approverarray = [];
    var index = -1;
    var ciname;

    var level1approver = new GlideRecord('cmdb_ci');
    level1approver.addQuery('assigned_to', 'CONTAINS', userSysId);
    level1approver.query();
    while (level1approver.next()) {
        var approver = level1approver.getValue('assigned_to');
        approverarray = approver.split(',');
        index = approverarray.indexOf(userSysId);
        ciname = level1approver.getValue('name');

        gs.eventQueue("Remove.inactive.users.from.Approver.fiel", current, ciname.toString(), approverarray);
        if (index > -1) {
            approverarray.splice(index, 1);
            level1approver.setValue('assigned_to', approverarray.join(','));
            level1approver.update();
        }
    }
5 REPLIES 5

@BanuMahalakshmi 

so what debugging have you done so far from your side?

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader