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

Willem
Giga Sage
Giga Sage

I have written an article about Client script for the MRVS:

https://community.servicenow.com/community?id=community_article&sys_id=f911162e1b6e1054d2ccea89bd4bc...

 

To clear the MRVS you just have to use like this:

g_form.setValue('variable_set_1', '');

variable_set_1 is the MRVS name

Although this method appears to clear out the mrvs rows as expected, the "Add" button on the mrvs remains disabled as though the maximum rows are still defined. I need to be able to remove the rows, and allow the users to add new ones.

Example:

  1. Define 'variable_set_1' with max_rows=1
  2. Add 1 row to 'variable_set_1', and observe that the "Add" button is disabled
  3. Run client script containing g_form.setValue('variable_set_1', '');
  4. Observe that rows are cleared, but the "Add" button remains disabled

I have also unsuccessfully tried adding the following to the client script following clearing the rows

  1. Adding g_form.setDisabled('variable_set_1', false);
  2. Adding g_form.setDisabled('mrvsIDAdd', false); where mrvsIDAdd is the element id of the button on the page

 

Can you try setting it to an empty array? It clears the MRVS for me. But I cannot check the limit row at the moment. Code is:

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

I wasn't clear in my post due to the way I noted it with <>. I tried the following prior to posting. 

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

If the variable set does not have a max_rows attribute or the user hasn't entered the maximum number of rows, the Add button remains enabled.

The issue arises when the user has added the maximum number of rows in the mrvs so that the Add button has been disabled. Once this has occurred, the Add button remains disabled even though the script clears out the rows using one of the above.

I was originally incorrect in my assessment of the situation. The problem isn't with clearing out the rows. It is with re-enabling the Add button.