Only want Edit option and hide remaining all buttons in pre-populated Multi Row Variable set

divyasurada
Tera Contributor

Hi,

I only want the user to have edit option in pre-populated MRVS in catalog item. Please suggest ways to do it using client script.

find_real_file.png

Thank you

1 ACCEPTED SOLUTION

Brad Bowman
Kilo Patron
Kilo Patron

An onLoad Catalog Client Script like this will work in both the native UI and Service Portal.  Ensure the Isolate script box is unchecked.  Increase the timeout if the MRVS is slow to load with the form.

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

    //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('multirow'); // Internal name of the MRVS
    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';
    }
  }
}

View solution in original post

2 REPLIES 2

Brad Bowman
Kilo Patron
Kilo Patron

An onLoad Catalog Client Script like this will work in both the native UI and Service Portal.  Ensure the Isolate script box is unchecked.  Increase the timeout if the MRVS is slow to load with the form.

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

    //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('multirow'); // Internal name of the MRVS
    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';
    }
  }
}

Ankur Bawiskar
Tera Patron
Tera Patron

@divyasurada 

the only way is DOM which is not recommended.

refer below link

Disable buttons in MultiRow Variable Set

Regards
Ankur

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