Hide Remove all button from MRVS

Brijmohan
Tera Contributor

Hi All and @Brad Bowman  I am auto populating some data in mrvs with the help of on change catalog client script. I want to hide '' Remove all '' button from MRVS so no one can delete the row from mrvs. I have tried the logic that I found from community in same script to hide the button but it is not working. PFB on change client script logic where I have added the  logic for hiding the button but it is not working. In alert I am getting portal.

 

Onchange function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }

    var poSysId = g_form.getValue('purchase_order_line');
    if (poSysId) {
        var ga = new GlideAjax('EditPurchaseOrder');
        ga.addParam('sysparm_name', 'getCostAllocationDetails');
        ga.addParam('poSysId', poSysId);
        ga.getXMLAnswer(function(response) {
            var data = JSON.parse(response);
            populateMRVS(data);
        });
    }

    function populateMRVS(data) {

        var mrvsData = [];

        data.forEach(function(record) {
            mrvsData.push({
                edit_cost_center: record.cost_center,
                edit_percentage: record.allocation_percentage
            });
        });

        // Convert the MRVS data to JSON string
        var mrvsJSON = JSON.stringify(mrvsData);
        g_form.setValue('edit_cost_centers', mrvsJSON);
    }

    //Hide remove all button
    var mrvsid = 'df00f3d01bc89e1051dba7d0b24bcb46'; //sys_id of MRVS
    if (window == null) { //Service Portal
        alert('portal');

        //hide Remove All button on MRVS
        var btn = this.document.getElementsByClassName("btn btn-default");
        for (i = 0; i < btn.length; i++) {
            if (btn[i].innerText == 'Remove All') {
                btn[i].style.display = 'None';
                //If you want to disable the button, but still show it, then use below line instead.
                //btn[i].disabled="disabled";
            }
        }

    } else { //native UI method
        alert('native');
        //hide only the Remove All button
        document.getElementById(mrvsid + 'removeAllRows').style.display = 'none';

    }

}

 

 

Also I have tried On load client script but this is also not working. Is the issue with logic like we need to remove check box separately that is present before each row. If yes then please help me how we can do that? PFB logic for on load client script. 

 

function onLoad() {
    //MRVS is loaded after the form is loaded. Hence setting a delay of 2 secs.
    setTimeout(function() {
        disableButtons();
    }, 5000);
}

function disableButtons() {
    var mrvsid = 'df00f3d01bc89e1051dba7d0b24bcb46'; //sys_id of MRVS
    if (window == null) { //Service Portal
    //alert('portal');

        //hide Remove All button on MRVS
        var btn = this.document.getElementsByClassName("btn btn-default");
        for (i = 0; i < btn.length; i++) {
            if (btn[i].innerText == 'Remove All') {
                btn[i].style.display = 'None';
                //If you want to disable the button, but still show it, then use below line instead.
                //btn[i].disabled="disabled";
            }
        }

    } else { //native UI method
                //alert('native');
        //hide only the Remove All button
        document.getElementById(mrvsid + 'removeAllRows').style.display = 'none';
       
    }
}

 

 

PFB MRVS snap.

 

Brijmohan_0-1724855309061.png

Thanks & regards,

Brijmohan

 

 

 

3 REPLIES 3

Community Alums
Not applicable

Hi @Community Alums, Thanks for your response. Will it work for all MRVS, because I required it only for mrvs that present in record producer? Also the above on load client is working fine when tried in PDI but not working in when I auto populating the data. 

 

PFB snap of PDI mrvs that created for test.

Brijmohan_0-1724857887845.png

 

PFB snap of mrvs in which code is not working.

Brijmohan_1-1724857939247.png

 

Community Alums
Not applicable

Hi @Brijmohan ,

it should work, try it