Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

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

Adam43
Tera Contributor

what if I'd like it to renumber when they delete rows or add new ones at the end during fulfillment?  can I just copy this as an onChange?

There's not a client/form way to identify/trigger a change in the contents of an MRVS.  What you can do is run a client script onSubmit of the request form/ritm/task that retrieves the MRVS (as JSON) then iterates through each row, resetting the value of this variable.