MRVS - detect deletion of Row or "Remove All"

poyntzj
Kilo Sage

We have a MRVS that exists and when the rows are updated we are running calling a routine from the parent Catalog Item to perform a calculation on the main form.

When a new row is added. the onSubmit routine runs, calls the script from the main catalog item and updates the parent form as expected.

However, we are unable to detect a deletion of a row, or a deletion of all rows

Not able to run a catalog client script on the main item as we cannot choose the MRVS as the "variable"

 

Any ideas ?

 

7 REPLIES 7

Brad Bowman
Kilo Patron
Kilo Patron

If you're not doing this in Service Portal you can capture when the Remove All button is clicked via an onLoad catalog client script on the main catalog item (not the MRVS).  Make sure the Isolate script box is not checked.

function onLoad() {
	document.getElementById('012264eadb589010a918196c299619e2removeAllRows').addEventListener("click", function(){   
   alert('RemoveAll clicked');
});
   
}

This is from my Orlando PDI, so use your browser developer tools to confirm the button ID.  If the MRVS is already populated when the form loads, you add this bit of magic to the same script to detect when a delete row icon is clicked

var mrvs = g_form.getValue('mrvs_internal_name'); 
	var obj = JSON.parse(mrvs);
	for (var i = 0; i < obj.length; i++) {
		document.getElementsByClassName('btn-sm multi-row-delete-row')[i].addEventListener("click", function(){   
   alert('Delete Row clicked');
});
	}

You could also use these first 3 lines to grab the contents of the MRVS onSubmit to detect when row(s) are deleted - vs the length from onLoad, though this wouldn't catch if a row is added then deleted before the form is saved.

 

Hi Brad, afraid it is the Service Portal

Staggered that so many things do not seem to work or be there for these - see some of my fun and games with catalog client scripts and mrvs.

 

I shall do some more investigations later as there maybe other options we can consider (order guide, widget)

For this code what is the ID? in getElementbyID which started with 012264...19e2?

function onLoad() {
	document.getElementById('012264eadb589010a918196c299619e2removeAllRows').addEventListener("click", function(){   
   alert('RemoveAll clicked');
});
   
}

  

Use your browser tools (in Chrome it's More Tools in the Menu, then Developer Tools (F11)) to inspect the Remove All button on the form, then this is the <button id=...