Remove row on MVRS is not updating in reference variable

Ash41
Kilo Sage

Hi Team, 

 

We are using a list collector variable based on selection under this variable, new rows are being added to the MVRS. If I'm trying to remove a row by clicking on x, it will remove record from MVRS table but not from the reference. Please help.

 

Regards, 

Ash

2 REPLIES 2

Brad Bowman
Kilo Patron
Kilo Patron

The tricky part about this is detecting when the x icon has been clicked.  I have used an onLoad Catalog Client Script to do this.  This example was at the Catalog Task level, so there's an opening if statement to determine if it is the catalog task on which the MRVS appears.  Obviously you won't need this if you are referring to the Catalog Item view or RITM.

function onLoad() {
	if(g_form.getValue('short_description') == "Procurement Assessment"){
		var mrvs = g_form.getValue('network_gear_model_mrvs'); //internal name of MRVS
		var obj = JSON.parse(mrvs);
		for (var i = 0; i < obj.length + 5; i++) {
			document.getElementsByClassName('btn-sm multi-row-delete-row')[i].addEventListener("click", function(){  
				g_form.setValue('v_row_deleted', 'Yes');
			});
		}
	}
}

I don't recall why I'm iterating for the number of MRVS rows + 5 - maybe this is to account for adding rows before deleting them?  The idea is this 'watches' for the icon to be clicked, then updates a Catalog Item variable.  Then you can have an onChange Catalog Client Script to reset this variable then loop through the remaining contents of the MRVS to push the variable value that contains the list collector value to an array and set the value of the list collector variable to the joined array.

Here's other possible solutions:

https://www.servicenow.com/community/developer-forum/mrvs-detect-when-a-row-is-removed-or-deleted/m-... 

Hi Brad, 

 I need this on Catalog item/ESC portal. Link is referring to create macro under widget, will you please guide on same?