Duplicating Data in Multi Row Variable Set

puneetgoels1
Tera Guru

On one of my catalog Item's Item View screen, if we select the number of Servers it automatically adds the same number of rows in MRVS with some default values.

 

Now the requirement:

Suppose user select 5 Servers, MRVS is updated with 5 rows with some default values.

User modifies the data in first row of MRVS, it should always replicate the data of few variables in the rest of the four rows?

 

3 REPLIES 3

Jace Benson
Mega Sage

Multi row variable sets store the data as  stringified array of objects, so if you want to 'set' the mrvs to have x rows when the number is changed you could just have a onchange client script do something like;

function onChange(...){
  // oldvalue!=newvalue bit
  // lets assume your mrvs has 3 variables in it, name, ip, and fqdn
  var emptyRow = {name: "example name", ip: "1.1.1.1", fqdn: "example.acme.com"};
  // now lets build that array;
  var returnArray = [];
  var numberOfServers = parseInt(newValue,10);
  for(var x = 0;x<numberOfServers;x++){
    returnArray.push(emptyRow)
  }
  returnArray = JSON.stringify(returnArray);
  g_form.setValue('yourMRVSnameHere', returnArray);
}

It is not on the change of any variable on the Item view form but when value is changed on the modal form of multi row variable set

Its not going to be easily possible.  Looks like this gets close but has no way to set the whole MRVS 

g_service_catalog - Client (servicenow.com)

Service catalog variable sets (servicenow.com)