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.

Issue Populating Variable Outside MRVS in OnChange Client Script

gautam_dhamija
Tera Contributor

I have a Multi-Row Variable Set (MRVS) in a record producer, and I'm trying to populate a variable outside the MRVS using an onChange client script. However, my script is not working as expected, and the variable is not getting updated.

gautam_dhamija_0-1738652715876.png

Set value function is not working

1 ACCEPTED SOLUTION

Brad Bowman
Kilo Patron
Kilo Patron

For whatever reason g_service_catalog does not (yet?) have a setValue method, only getValue.  You can set the value of a variable outside of the MRVS with a script like this, for the native UI and/or Service Portal/ESC/...

if (this) { //Service Portal method
    this.cat_g_form.setValue('advance_amount', '12');
} else { //native UI method
    parent.g_form.setValue('advance_amount', '12');
}

If you are using Service Portal, etc. you will also need this onLoad Catalog Client Script that Applies to the Catalog Item / Record Producer, not 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;
	}
}

View solution in original post

1 REPLY 1

Brad Bowman
Kilo Patron
Kilo Patron

For whatever reason g_service_catalog does not (yet?) have a setValue method, only getValue.  You can set the value of a variable outside of the MRVS with a script like this, for the native UI and/or Service Portal/ESC/...

if (this) { //Service Portal method
    this.cat_g_form.setValue('advance_amount', '12');
} else { //native UI method
    parent.g_form.setValue('advance_amount', '12');
}

If you are using Service Portal, etc. you will also need this onLoad Catalog Client Script that Applies to the Catalog Item / Record Producer, not 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;
	}
}