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

It appears the g_form.getField is only available for Mobile. I need this functionality for Mobile and Desktop. Do you know a way I can do this for both UI Types?

If you set UI Type to All, it works for both. I don't think it is only supported for mobile as i have done this earlier.

  • UI Type is set to All
  • Isolate script is set to false
  • Last message received from the following code snippet is "after clearing/before getfield"

Here is a snippet of the client script

g_form.addInfoMessage('before clearing');

g_form.setValue('variables.capacity_request_cpu', '[]');

g_form.addInfoMessage('after clearing/before getfield');

var my_var = g_form.getField('variables.capacity_request_cpu');

g_form.addInfoMessage('after getfield/before max_rows');

my_var.max_rows_size = 1; //allows upto 1. if you wnat more, incraes. i think max is 50

g_form.addInfoMessage('after max_rows');

use the MRVS name directly like this nad check.

var my_var = g_form.getField('capacity_request_cpu');

the script ends in the same location. Last message received is bolded below.

 

g_form.addInfoMessage('before clearing');
g_form.setValue('variables.capacity_request_cpu', '[]');
g_form.addInfoMessage('after clearing/before getfield');
var my_var = g_form.getField('capacity_request_cpu');
g_form.addInfoMessage('after getfield/before max_rows');
my_var.max_rows_size = 1; //allows upto 1. if you wnat more, incraes. i think max is 50
g_form.addInfoMessage('after max_rows');