how to copy previous row variable to new row in multirow variable set when users click on add

Chaiatnya
Tera Contributor

HI,

We have a requirement on Multirow variable set, when ever user clicks on add it should copy previous row variable to new row.

Can some one suggest how to achieve this

1 ACCEPTED SOLUTION

Brad Bowman
Kilo Patron
Kilo Patron

Hi Kri,

First you'll need an onLoad Catalog Client Script running on the Catalog Item itself, not within the MRVS.  Set the UI Type to All.

function onLoad() {
	if (this) {//we only need to do this for Service Portal
		//We need to make the g_form object for the parent item available from the MRVS window
		this.cat_g_form = g_form;
	}
}

Now within the MRVS we can create an onLoad Catalog Client Script within the MRVS, also with the UI Type = All.

function onLoad() {
	var mrvs = '';
	if (this) {//Service Portal method
		mrvs = this.cat_g_form.getValue('mrvs1');//internal name of your MRVS
	}
	else{//native UI method
		mrvs = parent.g_form.getValue('mrvs1');
	}
	if(mrvs.length > 2){//native UI returns [] for empty MRVS value
		var obj = JSON.parse(mrvs);
		g_form.setValue('test_1', obj[obj.length-1].test_1);//name of the first MRVS variable to autopopulate
		g_form.setValue('test_2', obj[obj.length-1].test_2);
	}
}

View solution in original post

8 REPLIES 8

Brad Bowman
Kilo Patron
Kilo Patron

Hi Kri,

First you'll need an onLoad Catalog Client Script running on the Catalog Item itself, not within the MRVS.  Set the UI Type to All.

function onLoad() {
	if (this) {//we only need to do this for Service Portal
		//We need to make the g_form object for the parent item available from the MRVS window
		this.cat_g_form = g_form;
	}
}

Now within the MRVS we can create an onLoad Catalog Client Script within the MRVS, also with the UI Type = All.

function onLoad() {
	var mrvs = '';
	if (this) {//Service Portal method
		mrvs = this.cat_g_form.getValue('mrvs1');//internal name of your MRVS
	}
	else{//native UI method
		mrvs = parent.g_form.getValue('mrvs1');
	}
	if(mrvs.length > 2){//native UI returns [] for empty MRVS value
		var obj = JSON.parse(mrvs);
		g_form.setValue('test_1', obj[obj.length-1].test_1);//name of the first MRVS variable to autopopulate
		g_form.setValue('test_2', obj[obj.length-1].test_2);
	}
}

Thanks Brad, It worked

You are welcome.

It is working..