Allowing HR Admins to delete multiple HR Case records from list view

Cameron Wilson
Tera Expert

We are trying to figure out why HR Admins are unable to delete multiple HR Case records from the list view using the "Actions on selected rows..." drop-down list. They can delete a record if they are in it, just not multiple. The role is on the "Delete" ACL for the table so they have the access to delete records using the UI Action button in the record.

We would like for them to have the ability to delete multiple but only from the HR Core Case Table and not any other tables.

When on the list view they can see the option in the "Actions on selected rows..." drop-down list but is grayed out.

 

find_real_file.png

1 ACCEPTED SOLUTION

Cameron Wilson
Tera Expert

I found a solution to this and coming back here as I realized I could include it so that it may help someone else.

 

I ended up creating a new UI Action for the HR Case table copied from another UI Action that does the same/similar for other tables. This UI Action while on the HR Case table is applied to the Global scope but also takes into account the conditions if the user can delete (from Delete ACL) and has the HR Admin role. This way they do not have the ability to delete multiple records from other tables in the Global Scope such as Incident as an example. NOTE: this had to be done from the Global Scope and NOT from within the HR scope so keep that in mind.

 

Below is a screenshot of the values I used for the UI Action and the script.

 

Delete UI Action for HR Case.jpg

var tblName;
var ajaxHelper;
var selSysIds;
var sysIdList;
var indx = 0;
var numSel = 0;

function confirmAndDeleteFromList() {
    tblName = g_list.getTableName();
    selSysIds = g_list.getChecked();
    sysIdList = selSysIds.split(',');
    numSel = sysIdList.length;

    if (numSel > 0) {
        indx = 0;
        ajaxHelper = new GlideAjax('DeleteRecordAjax');
        getCascadeDeleteTables();
    }
}

function getCascadeDeleteTables() {
    if (sysIdList[indx] != '') {
        ajaxHelper.addParam('sysparm_name', 'getCascadeDeleteTables');
        ajaxHelper.addParam('sysparm_obj_id', sysIdList[indx]);
        ajaxHelper.addParam('sysparm_table_name', tblName);
        ajaxHelper.addParam('sysparm_nameofstack', null);
        ajaxHelper.getXMLAnswer(getCascadeDelTablesDoneList.bind(this), null, null);
    }
}

function getCascadeDelTablesDoneList(answer, s) {
    var delObjList = '';
    var selObjName = '';

    if (answer != '') {
        var ansrArray = answer.split(';');
        if (ansrArray.length > 1) selObjName = ansrArray[1];
        if (ansrArray.length > 2) delObjList = ansrArray[2];
    }

    if (delObjList != '') {
        if (numSel > 1) {
            showListConfDlg("true", selObjName, delObjList);
        } else {
            showListConfDlg("true", '', delObjList);
        }

    } else {
        indx++;
        if (indx < numSel) {
            ajaxHelper.addParam('sysparm_name', 'getCascadeDeleteTables');
            ajaxHelper.addParam('sysparm_table_name', tblName);
            ajaxHelper.addParam('sysparm_obj_id', sysIdList[indx]);
            ajaxHelper.getXMLAnswer(getCascadeDelTablesDoneList.bind(this), null, null);
        } else {
            showListConfDlg("false", '');
        }
    }
}

function showListConfDlg(hasCascadeDel, selObjName, delObjList) {
    var dialogClass = typeof GlideModal != 'undefined' ? GlideModal : GlideDialogWindow;
    var dlg = new dialogClass('delete_confirm_list');
    dlg.setTitle('Confirmation');
    if (delObjList == null) {
        dlg.setWidth(300);
    } else {
        dlg.setWidth(450);
    }

    dlg.setPreference('sysparm_obj_list', selSysIds);
    dlg.setPreference('sysparm_table_name', tblName);
    dlg.setPreference('sysparm_has_cascade_del', hasCascadeDel);
    dlg.setPreference('sysparm_sel_obj_name', selObjName);
    dlg.setPreference('sysparm_del_obj_list', delObjList);
    dlg.render();
}

 After selecting the records to delete they can go into the  "Actions on selected rows..." drop-down list and the 'Delete' option is no longer greyed out and they will get a Confirmation pop-up prompt, "Delete the selected record(s)" with the options to 'Cancel' or 'Delete'. Depending on the number of records to delete it may take a few seconds to see the prompt so just be patient. 🙂 

View solution in original post

3 REPLIES 3

Sukraj Raikhraj
Kilo Sage

if one item is selected, is the option to delete not grayed out?

No even if one is selected it is still grayed out. The only way they are able to delete is if they open and go into the record and then they can delete using the delete button. 

Cameron Wilson
Tera Expert

I found a solution to this and coming back here as I realized I could include it so that it may help someone else.

 

I ended up creating a new UI Action for the HR Case table copied from another UI Action that does the same/similar for other tables. This UI Action while on the HR Case table is applied to the Global scope but also takes into account the conditions if the user can delete (from Delete ACL) and has the HR Admin role. This way they do not have the ability to delete multiple records from other tables in the Global Scope such as Incident as an example. NOTE: this had to be done from the Global Scope and NOT from within the HR scope so keep that in mind.

 

Below is a screenshot of the values I used for the UI Action and the script.

 

Delete UI Action for HR Case.jpg

var tblName;
var ajaxHelper;
var selSysIds;
var sysIdList;
var indx = 0;
var numSel = 0;

function confirmAndDeleteFromList() {
    tblName = g_list.getTableName();
    selSysIds = g_list.getChecked();
    sysIdList = selSysIds.split(',');
    numSel = sysIdList.length;

    if (numSel > 0) {
        indx = 0;
        ajaxHelper = new GlideAjax('DeleteRecordAjax');
        getCascadeDeleteTables();
    }
}

function getCascadeDeleteTables() {
    if (sysIdList[indx] != '') {
        ajaxHelper.addParam('sysparm_name', 'getCascadeDeleteTables');
        ajaxHelper.addParam('sysparm_obj_id', sysIdList[indx]);
        ajaxHelper.addParam('sysparm_table_name', tblName);
        ajaxHelper.addParam('sysparm_nameofstack', null);
        ajaxHelper.getXMLAnswer(getCascadeDelTablesDoneList.bind(this), null, null);
    }
}

function getCascadeDelTablesDoneList(answer, s) {
    var delObjList = '';
    var selObjName = '';

    if (answer != '') {
        var ansrArray = answer.split(';');
        if (ansrArray.length > 1) selObjName = ansrArray[1];
        if (ansrArray.length > 2) delObjList = ansrArray[2];
    }

    if (delObjList != '') {
        if (numSel > 1) {
            showListConfDlg("true", selObjName, delObjList);
        } else {
            showListConfDlg("true", '', delObjList);
        }

    } else {
        indx++;
        if (indx < numSel) {
            ajaxHelper.addParam('sysparm_name', 'getCascadeDeleteTables');
            ajaxHelper.addParam('sysparm_table_name', tblName);
            ajaxHelper.addParam('sysparm_obj_id', sysIdList[indx]);
            ajaxHelper.getXMLAnswer(getCascadeDelTablesDoneList.bind(this), null, null);
        } else {
            showListConfDlg("false", '');
        }
    }
}

function showListConfDlg(hasCascadeDel, selObjName, delObjList) {
    var dialogClass = typeof GlideModal != 'undefined' ? GlideModal : GlideDialogWindow;
    var dlg = new dialogClass('delete_confirm_list');
    dlg.setTitle('Confirmation');
    if (delObjList == null) {
        dlg.setWidth(300);
    } else {
        dlg.setWidth(450);
    }

    dlg.setPreference('sysparm_obj_list', selSysIds);
    dlg.setPreference('sysparm_table_name', tblName);
    dlg.setPreference('sysparm_has_cascade_del', hasCascadeDel);
    dlg.setPreference('sysparm_sel_obj_name', selObjName);
    dlg.setPreference('sysparm_del_obj_list', delObjList);
    dlg.render();
}

 After selecting the records to delete they can go into the  "Actions on selected rows..." drop-down list and the 'Delete' option is no longer greyed out and they will get a Confirmation pop-up prompt, "Delete the selected record(s)" with the options to 'Cancel' or 'Delete'. Depending on the number of records to delete it may take a few seconds to see the prompt so just be patient. 🙂