
- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
on 08-26-2020 11:48 AM
Hi,
In this article, I will show how you can disable the buttons or icons in the multirow variable set.
Generally, when we add MRVS, we see few buttons which cannot be customized easily and they are
- Add
- Remove All
- Edit icon
- Delete icon
I will show you few examples on how you can manage to hide/disable these buttons/icons.
Add Button
As we all know the add button is used to add rows to MRVS. But in some cases, when we are auto-populating the MRVS from backend, then we might not want the user to add new rows or if you want to limit the number of rows that can be added by the user (let say 5). In such cases, how do disable this button?
There is this property max_rows_size of MRVS which we should use to disable the Add button.
//Add these lines in your onload catalog client script
var my_var = g_form.getField("my_var_set");//use your variable set name here
//The number below indicates after how many rows, the add button to disaable.
//If you want to limit to 5 rows then mention 5 below.
//If you put 0, it will disable Add button without checking the rows.
my_var.max_rows_size = 5;
Remove Button
How to disable/hide Remove Button. Unfortunately there is no direct way to do this. We have to handle this through DOM or page specific CSS. I will show you how you can do it through DOM.
function onLoad() {
//MRVS is loaded after the catalog item is loaded. Hence setting a delay of 2 secs.
setTimeout(function() {
disableButtons();
}, 2000);
}
function disableButtons() {
var my_var = g_form.getField("my_var_set");//use your variable set name here
my_var.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].disabled="disabled";
//If you want to hide it fully, then use below line.
//btn[i].style.display='None';
}
}
//if you want to hide Add button as well, you can use above logic,
// but use the class name as btn-primary instead of btn-default
//and change the if condition to Add.
}
Disable Edit and Remove icons
If you do not want the multirow variable set data to be edited, then it is easier. You can simply create a catalog UI policy on your catalog item and under scripts add these 2 lines of code.
function onCondition() {
var my_var = g_form.getField("my_var_set");//use your variable set name here
g_form.setReadOnly('my_var_set',true);
}
This will make the variable set read-only and hide the edit/delete/add and remove all buttons.
But if you want to hide one of the icons like edit or just hide X icon, then we need to handle this through DOM. The logic is similar to how we hide the button, but here since its a link, we will not have any text. So we need to access the title attribute of these icons and compare. Look at the below sample code.
function onLoad() {
//MRVS is loaded after the catalog item is loaded. Hence setting a delay of 2 secs.
setTimeout(function() {
disableButtons();
}, 2000);
}
function disableButtons() {
var my_var = g_form.getField("my_var_set");//use your variable set name here
var icon = this.document.getElementsByClassName("wrapper-xs fa fa-close");
for (i = 0; i < icon.length; i++) {
if(icon[i].getAttribute("title") == 'Remove Row') {
icon[i].style.display='None';
}
}
//To hide Edit icon, then use the class name as fa-pencil instead of fa-close
}
Let me know if you have any questions in the comments below.
Related MRVS articles that I Wrote:
- Populate the value of a field of Catalog item into the Multi Row Variable Set
- How to add rows dynamically in Multi Row Variable set (MRVS) based on input value of Catalog item
- Prefill data in Multi Row Variable Sets
Mark the article as helpful and bookmark if you found it useful.
Regards,
Asif
2020 ServiceNow Community MVP
- 29,136 Views
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hello
Thank you very much for the article. I am trying to hide just the "Remove row" icon and not the "Edit" icon. I would like to know if this code works on Catalog Item in portal too while adding rows to the MVRS?
Thanks
Harish Gubba

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi Harish
yes it will work. Just ensure, that you use the right class name for edit which i think is fa-pencil and also the title will be different. Check and make changes in the code and it will work.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
I tried to hide the Add button with an onLoad client script but it isnt working. I use the internal name of my MRVS too. Can you maybe provide screen shots or details? I think something is missing in your instructions. I tried the client script in 2 different places. First in the catalog item. Then when that didnt work I tried a client script inside the variable set. Neither worked.
function onLoad() {
var my_var = g_form.getField('my_test_mrvs');
my_var.max_rows_size = 0;
}
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Yes, I faced the same issue while onLoad() script. But, onChange() it was working fine and my current Business Requirement is to Remove "Add" button only when another field is filled with some value. So, It worked for me in that way.

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Did you guys use the timeout as i have mentioned in my code? it is becuase, when you use onload, first the catalog item loads. After that the MRVS gets loaded. So by the time your script executes the MRVS is not loaded fully yet. hence it will not work.
So add a timeout of 1-2 secs and then check. it will work.
Mark comment as helpful if it helps.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Is it possible to Disable the Add button in POP up which will come when we are adding values to Multi Row variable Set
It should only be active when the conditions are fulfilled

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
The popup comes only when you click on Add button. Which popup are you referring to? Can you share a screenshot.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Yes I was asking about the Pop-up which will come after clicking on Add buttton,
When the Pop Up appears is there any way to Disable the Add Button in the pop up
if certain conditions are passed then only to enable again

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi,
Write onload Catalog client script on your variable set and in that try to disable the button using my code and try it. If it does not work, please create a question and we can check it.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Thank you for this information, it is very good. The onLoad script works for me (disabling delete), but when I update the MRVS via a script, all the buttons reset and become available. I have tried to disable them in an onChange script, but am not able to get it working.
Anyone have any tips or has gotten this to work? Thank you.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hello All!
No doubt you have seen all the posts scattered around by asifnoor to this well intentioned post. I want to thank asifnoor for this helpful post and I want to add an alternative solution that worked really well for me (I was not able to make his solution work).
There was a post by
The solution for removing buttons is Not reliant on an OnLoad script. In fact, I was able to get this to work on an onChange Script (on the Cat Item) AFTER I had dynamically updated the MRVS.
BIG THANKS TO COYOTERAY! PLEASE GO MARK HIS POST AS HELPFUL!!!
Here is his code for removing the 'Add' & 'Remove All' buttons:
function onLoad() {
//Type appropriate comment here, and begin script below
setTimeout(function () {
//hide the add/remove table
var z = this.document.getElementsByClassName("sc-table-variable-buttons");
// alert(z.length);
var k;
for (k = 0; k < z.length; k++) {
z[k].style.display = 'none';
}
}, 1000);
}
Here is his code for removing all the 'x' editing buttons:
var y = this.document.getElementsByClassName("btn btn-sm icon-cross multi-row-delete-row");
// alert(y.length);
var j;
for (j = 0; j < y.length; j++) {
y[j].style.display = 'none';
}
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
HI, i am trying to remove the x Remove row in an Onload Client script.
Tried above solutions but now working. How to do this? We're in madrid version

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Kindly create a question and share your script. I will look into it.

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Thank you! This works perfectly for CMS. Any chance you know how to make the above work for Portal?
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi
Did you get any solution for this? Could you please share if you got.

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Any solution on how to make this work on Portal? Thank you.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Glad it worked for you in CMS. Unfortunately we had some custom Portal work done for us, which is not OOB SN Portal. So I may not be able to help much.
This solution still works for me in our Portal configuration, which as mentioned is not entirely OOB. I would suggest that you use your browser dev tools to inspect the portal page and try to find the class name for the button. The code is the same and its still defined in Client Scripts, I just make sure that the class name is correct. I know the class names in RITMs for the buttons change for sure, I am wondering if the same is for the Portal.
Hope that helps.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi , Any solution for portal? I have same requiremet
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi, did you try setting max_rows attribute in Variable Set attributes field of Multi Row Variable Set. It works in platform as well as portal to disable Add button after specific number of rows added
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi isela,
I tried something on portal. If you are using only mrvs through out the catalog item, then this will work. But incase you need these options to be hidden for one mrvs and visible for other, then I am afraid it will hide for all.
try:-
Create a widget with client script:-
api.controller=function($scope) {
/* widget controller */
var c = this;
$scope.$watch(function(){
var editOption = document.getElementsByClassName('wrapper-xs fa fa-pencil');
for (var i = 0; i < editOption.length; i ++) {
editOption[i].style.visibility = 'hidden';
}
return false;
}, function(value){
});
};
Mark answer correct
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
On Portal, you can use a catalog client script to inject style sheet entries to hide the edit or delete icons. here's my onLoad script to hide the Add and RemoveAll buttons as well as the row-level delete buttons for my pre-populated MRVS:
function onLoad() {
var sheets = this.document.styleSheets;
var sheet = sheets[0];
//This hides the row-level buttons
sheet.insertRule('a.fa-close { display: none !important; }');
//This hides the Add/Remove All buttons, use your internal MRVS name
sheet.insertRule('#MRVS_INTERNAL_NAME button { display: none !important; }');
}
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Your provided solution for "Disable Edit and Remove icons" works perfect. We have the issue that the buttons "Edit" and "Remove" icons on a variable set were not disabled on RITM and catalog task level although we used a catalog ui policy to read-only the variable set. The code works.
Thank you so much for that!
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
I love the post on how to hide/disable/etc.
What I haven't seen is a way to add NEW black rows to the MRV table once created.
Is there a way to add/update the ADD button so that it can prompt user to "Add Another Record" or Stop?
For ease of use, having to add rows one at a time is a bit tedious.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hello,
Sharing what I came up with after looking at the different posts. Thanks for all the input.
- This will hide the main button or row icons depending on the initial settings you require (hide_removeall, hide_add, ...), variables at beginning of script.
- This works for Desktop and portal UI
- It's not direct DOM access so you don't have to "Isolate script"
- Seems to work without setTimeout on my side
function onLoad() {
//Type appropriate comment here, and begin script below
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
}
var hide_removeall=true;
var hide_add=true;
var hide_deleterow=true;
var hide_editrow=true;
var mrvsname='put_your_mrvs_name_here';
var mrvsid='sys_id of mrvs';// sys_id of the mrvs is required when client script has to be executed on requested item or catalog task
// For ServicePortal we create styleSheet rule - Edit / Remove row icon will always be hidden on row insert
if (window === null) {
var sheets = this.document.styleSheets;
var sheet = sheets[0];
var rule_params=[];
if (hide_removeall) { rule_params.push('#' + mrvsname + ' .btn-default'); }
if (hide_add) { rule_params.push('#' + mrvsname + ' .btn-primary'); }
if (hide_deleterow) { rule_params.push('#' + mrvsname + ' .fa-close'); }
if (hide_editrow) { rule_params.push('#' + mrvsname + ' .fa-pencil'); }
sheet.insertRule(rule_params.toString() + ' { display: none !important; }');
} else {
// On Desktop UI - Edit / Remove row icon won't be hidden on row insert, it will only apply to existing rows
// for main button we can access the Elements directly
if (hide_removeall) { g_form.getElement(mrvsid + 'removeAllRows').hide(); }
if (hide_add) { g_form.getElement(mrvsid + 'Add').hide(); }
// for row icons we need to get the element then update each row
if (hide_deleterow || hide_editrow) {
var rows=g_form.getElement(mrvsid + 'Add').getOffsetParent().getElementsByClassName('sc-multi-row-actions');
for (i_row=0;i_row<rows.length;i_row++) {
var icons=rows[i_row].getElementsByClassName('btn');
if (hide_editrow) { icons[0].hide(); }
if (hide_deleterow) { icons[1].hide(); }
}
}
}
}
When on Desktop UI i still need to find how to hide the row icons when new rows get inserted, if you have any hints...
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Thanks It worked for me without scripting 🙂
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
For newer versions:
// Dom manipulation
var htmlDoc = false;
if (top.document.getElementById('gsft_main'))
htmlDoc = top.document.getElementById('gsft_main').contentWindow.document;
if (!htmlDoc) {
if (document) { htmlDoc = document; }
else if (top) { htmlDoc = top.document; }
}
// Add and Remove All
if (htmlDoc) {
htmlDoc.querySelector('.sc-table-variable-buttons').hide();
setTimeout(function() {
// delete button
htmlDoc.querySelectorAll('.multi-row-delete-row').forEach(function(el) { el.hide(); });
// edit button
// htmlDoc.querySelectorAll('.sc-multi-row-actions > .icon-edit').forEach(function(el) { el.hide(); });
// both buttons (and also the column)
// htmlDoc.querySelectorAll('.sc-multi-row-actions').forEach(function(el) { el.hide(); });
// htmlDoc.querySelector('.sc-table-variable-header:first-child').hide();
}, 250);
}

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
How can I make this work on a specific MRVS, I have five different MRVS, and I need to work only on one of them.
Thanks
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi Gabriel,
Thank you for this segment! It is super helpful. However, I've been struggling to only hide the "Remove all" button. Do you have any idea on how to do it?
Thanks in advance.
Edit: GetElementById() did the trick!
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
How to hide buttons in Multi-Row Variable Sets (MRVS) without DOM manipulation
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Can you please let us know how we can disable the add and remove buttons in the workspace? As the current solution is not working in the workspace.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
On the Washington D.C. release it looks like getField() is either deprecated or my instance doesn't support this function. Most of what Asifnoor wrote still applies, but I had to remove the getField() references to avoid errors in the console.
Here's an example of what I used to hide the Add, Remove All, and Remove Row icons/buttons.
setTimeout(disableButton, 2000);
function disableButton() {
//Disables and Hides the Add button on the Catalog Multi-Row Variable Set var iconAdd = this.document.getElementsByClassName("btn btn-primary m-r");
for (var z = 0; z < 1; z++) {
if (iconAdd[z].innerText == 'Add') {
iconAdd[z].disabled = "disabled";
iconAdd[z].style.display = 'None';
}
}
//Disables and Hides the Remove Row 'x' icon on each Row of the Catalog Multi-Row Variables Set
//Note: referencing the document like this is not good practice and this has already broken once when the "aria-label" field changed from "Remove Row" to "Remove Row #" where the number appears to be the number of the row we're looking at. Unfortunately, I haven't been able to find a solution that doesn't use dom manipulation.
var icon = this.document.getElementsByClassName("wrapper-xs fa fa-close");
for (var i = 0; i < arrayOfMRVSRows.length; i++) {
if (icon[i].getAttribute("aria-label") == 'Remove Row ' + (i + 1)) {
icon[i].disabled = "disabled";
icon[i].style.display = 'None';
}
}
//Disables and Hides the Remove All button on the Catalog Multi-Row Variable Set
var iconR = this.document.getElementsByClassName("btn btn-default");
for (var z = 0; z < 4; z++) {
if (iconR[z].innerText == 'Remove All') {
iconR[z].disabled = "disabled";
iconR[z].style.display = 'None';
}
}
}
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
I don't know if this was already present as a solution.
Create a UI policy for your desired condition, create a UI policy action and select the Variable set and make it read only. It makes the variable set read only and disables all the buttons on it.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
is there any way to hide the whole column using DOM manipulation only on the Catalog item view
can anyone provide the code