Auto add row to multi row variable set

Jeff316
Kilo Guru

Hi All,

I'm using the new multi-row variable set on a catalog request form.

This catalog request is for a new server.

The intake form uses the multi-row variable set so the users can enter a list of servers with drive letter, size, etc...

I need to automatically add 1 or 2 rows for the user based on other logic.

For example, if they select Windows as the OS, then automatically in the multi-row variable set for "Drives Needed" I have to start them with a row for the C drive with some preset size attribute.

The user is free to "add" more drives needed for the server but I will automatically have added the C drive.

if they pick "unix" as the OS in another variable on the form then I need to automatically insert a different drive.

Where and how do I insert the "default" drives into the multi-row variable on the screen so to the user, it appears they already requested the default drive.

find_real_file.png

1 ACCEPTED SOLUTION

Jace Benson
Mega Sage

You just need to make a an onChange script on the item for the OS variable.

Your onChange script will probably have code like this;

var drives = [
  {
    drive: "L:",
    size: "test",
    unit: "GBs",
    tier: "Premium_LRS"
  }
];

g_form.setValue('variableSetName', JSON.stringify(drives));

View solution in original post

7 REPLIES 7

Jace Benson
Mega Sage

You just need to make a an onChange script on the item for the OS variable.

Your onChange script will probably have code like this;

var drives = [
  {
    drive: "L:",
    size: "test",
    unit: "GBs",
    tier: "Premium_LRS"
  }
];

g_form.setValue('variableSetName', JSON.stringify(drives));

That's good. So once they pick the OS in my case, the on change script will dynamically add that row to the multi-row variable set displayed on the screen as if they entered those values. Thank you very much. I appreciate it. I'm going to give it a try tomorrow.

It will set the multirow variable set to only that value.  They can add after, but if they added before it would drop it.  If you want to add to it, you'll need to interpt the value first.

Something like;

var variableSetName = 'putYourVariableSetNameHere';
var drives = JSON.parse(g_form.getValue(variableSetName));
var drives.push(
  {
    drive: "L:",
    size: "test",
    unit: "GBs",
    tier: "Premium_LRS"
  }
);

g_form.setValue(variableSetName, JSON.stringify(drives));

Jace,

 The script works perfectly.

I then added a second mrvs to this catalog item for os_drives with 5 variables but I changed their variable names by adding _os to the end, so I'm not called the mrvs the same name nor any of the variables on those mrvs.

Both catalog client scripts fire on change when the person selects the OS.

The first, original mrvs gets updated and the row inserts but the second mrvs script thrown an error:

TypeError: Converting circular structure to JSON

 Is there some reason I can't have 2 client scripts on change both insert a row into a different mrvs on the catalog item?

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}

var drives = [
{
drive_letter: "CC",
drive_size: "test",
unit: "GBs",
disk_tier: "Premium_LRS",
sizeingbs: "333"
}
];

g_form.setValue('drives', JSON.stringify(drives));

}