How to increase row number automatically when we click on the "Add" UI action on the MRVS?

antony4007
Tera Expert

Hi Expert,

How to increase row number automatically when we click on the "Add" UI action on the MRVS? is it possible?

In the below screenshot, i added the row(1,2) manually.

find_real_file.png

 

Thanks,

Antony

1 ACCEPTED SOLUTION

Brad Bowman
Kilo Patron
Kilo Patron

Hi Antony,

These scripts will get you there, but you could be welcoming trouble due to the ability to edit and delete rows - so user actions could cause the row numbers to appear out of order.  You can make this variable read-only and resort the MRVS or re-number the Row variable onSubmit if that's an issue.

First, if you're using Service Portal, you'll need an onLoad Catalog Client Script that Applies to the Catalog Item, not within the MRVS.

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;
	}
}

 

 Next, an onLoad Catalog Client Script that Applies to the Variable Set:

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('v_row', parseInt(obj[obj.length-1].v_row) + 1); //your variable name
	}
	else {
		g_form.setValue('v_row', '1');
	}
}

View solution in original post

7 REPLIES 7

Ravi9
ServiceNow Employee
ServiceNow Employee

can you elaborate a bit more ? what are you looking for exactly?

Hi Ravi,

 

Thanks for your response. The requirement is when i click on the "Add" button to add the row into MRVS, the below page will popup

find_real_file.png

Then the row field should be auto populate as 1. When i add the second row in the MRVS, the row field should auto populate to 2. likewise the row field value has to auto increase whenever we add a new row into the MRVS.

 

Thanks,
Antony

Brad Bowman
Kilo Patron
Kilo Patron

Hi Antony,

These scripts will get you there, but you could be welcoming trouble due to the ability to edit and delete rows - so user actions could cause the row numbers to appear out of order.  You can make this variable read-only and resort the MRVS or re-number the Row variable onSubmit if that's an issue.

First, if you're using Service Portal, you'll need an onLoad Catalog Client Script that Applies to the Catalog Item, not within the MRVS.

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;
	}
}

 

 Next, an onLoad Catalog Client Script that Applies to the Variable Set:

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('v_row', parseInt(obj[obj.length-1].v_row) + 1); //your variable name
	}
	else {
		g_form.setValue('v_row', '1');
	}
}

Hi Brad,

 

It worked fine. And yes its not re-numbering when we delete the row in between. I will talk to the client for the re-numbering part.

 

Thanks,

Antony