How do I "Remove All" multirow variable set rows using a client script?

kevinharalson
Mega Expert

I need a client script for use in an onChange function to remove all rows from a multirow variable set.

Scenario

  1. A user will select a CI in a catalog item, and add maximum rows to a multirow variable set based on max_rows attribute.
  2. Then, the user realizes the wrong CI was selected, and changes the selected CI
  3. Upon selection of a new CI, I need a client script to remove all rows from the multirow variable set and enable the "Add" button.

I have tried the following without success

  • g_form.setValue(< mrvs name>, '');
  • g_form.setValue(< mrvs name>, '[]');
  • g_form.clearValue(< mrvs name>);

In all instances the information is removed, but the "Add" button remains disabled.

1 ACCEPTED SOLUTION
30 REPLIES 30

How are you disabling the Add button? I have set the max_rows property and still the Add button is available. It just removes the line. Is there a client script you are using to do this?

If you set max_rows=2, once the user adds 2 rows to the mrvs, the "Add" button is automatically disabled.

Removing a single row by clicking the "X" or removing all by clicking the "Remove all" button will reactivate the "Add" button, but I do not know the script performing the reactivation.

@kevinharalson I think I have found it!

All our attempts returned an error when I tried to get the row count afterwards. So I used my article and reversed engineered it.

With this code it has row count 0:

g_form.setValue('variable_set_1', JSON.stringify([]));

Let me know if this works for your Add button as well! 🙂

This did not re-enable the Add button either.

asifnoor
Kilo Patron

Hello

 

After removing the values.. you need to set the value for max_rows_size to a positive value for Add to be enabled. 

Mark the comment as a correct answer and helpful if it helps.