How to keep MRVS readonly with remove all button?

Sri56
Tera Contributor

Hi All,

 

We have a requirement where we have to keep the MRVS readonly.

if we do so, even add/ remove all button is hiding.

But we need to hide add button and keep 'remove all' button or any sort of delete action to remove all entries.

 

How can we achieve this one?

Please help!

 

Thanks,

Sri

7 REPLIES 7

Brad Bowman
Kilo Patron
Kilo Patron

Hi Sri,

You'll want to remove any script or policy that you have to make the MRVS read only.  Instead, run an onLoad Catalog Client Script to hide the buttons that you want hidden - so in your case there will not be the ability to add a row, edit existing rows, or delete each single row if that's what you want.  There are a few nuances to hiding the buttons, so try something like this for starters.  This version works in Portal and the native UI.  After saving the script ensure that the Isolate script box is unchecked.

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

function disableButtons() {
  var mrvsid = '2410eeb22fe66490cbe6fe7cf699b6d9';//sys_id of MRVS
  if(window == null){//Service Portal
  
	//hide Add button on MRVS
    this.document.getElementById(mrvsid + '_add_row').style.display = 'none';
    
	//hide Remove All button on MRVS
    var mrvs = g_form.getField("mrvs1");//internal name of MRVS
	mrvs.max_rows_size = 0;
	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";
		}
	}

    //Hide each X (delete row) icon on MRVS
    var icon = this.document.getElementsByClassName("wrapper-xs fa fa-close");
    for(j=0; j<icon.length; j++){
      if(icon[j].getAttribute("title") == 'Remove Row'){
        icon[j].style.display='None';
      }
    } 
  }
  else{//native UI method
    //hide Add and Remove All buttons on MRVS
    document.getElementById('table_variable_buttons_' + mrvsid).style.display = 'none';
    //hide only the Add button 
    //document.getElementById(mrvsid + 'Add').style.display = 'none';
    //hide only the Remove All button
    //document.getElementById(mrvsid + 'removeAllRows').style.display = 'none';
    //hide delete and/or edit icon/button on each row of MRVS
	var mrvs = g_form.getValue('mrvs1');
    var obj = JSON.parse(mrvs);
    for (var i = 0; i < obj.length; i++) {
      //delete - check Name, may be 'cross' instead	
      document.getElementsByClassName('btn-sm multi-row-delete-row')[i].style.display = 'none';
      //edit	
      document.getElementsByClassName('btn icon-edit btn-sm')[i].style.display = 'none';
    }
  }	  
}

 

Thanks Brad for the quick response.

Now i successfully hidden add button.

But still edit and x icons displays as actions inside service portal.

And above code is not working to remove them.

 

Please help!

 

Thanks,

Sri

It looks like the attribute "title" has been changed to "data-original-title" so this block will hide the edit and delete icons in service portal

 

    //Hide each X (delete row) icon on MRVS
    var icon = this.document.getElementsByClassName("wrapper-xs fa fa-close");
    for(j=0; j<icon.length; j++){
      if(icon[j].getAttribute("data-original-title") == 'Remove Row'){
        icon[j].style.display='None';
      }
    }
 
	//Hide each pencil (edit row) icon on MRVS
    var iconedit = this.document.getElementsByClassName("wrapper-xs fa fa-pencil");
    for(k=0; k<iconedit.length; k++){
      if(iconedit[k].getAttribute("data-original-title") == 'Edit Row'){
        iconedit[k].style.display='None';
      }
    }

Hi Brad,

 

Still its not working.

Please help!

 

Thanks,

Sri