Sometimes you need to share values between variables in the main form and a Multi Row Variable Set.
Each Multi Row Variable Set has its own instance of g_form that cannot access the data in the main form.
This restriction can be solved by making the main g_form instance available to the MRVS.
The code will differ a bit between the backend and the Service Portal.
Backend
The variable set is opened in a new iFrame.
Accessing the main g_form only requires accessing the parent variable.
For instance, we can create an onLoad Catalog Client Script on the MRVS that gets the value from a variable in the main form and set it in the new row.
if(parent.g_form){ g_form.setValue('to', parent.g_form.getValue('from')); }
Service Portal
It is a bit more complicated in Service Portal. The popup is not opened in an iframe, so we will need two steps to achieve the same result.
Making main g_form available
We can set the g_form as a global variable in an onLoad Catalog Client Script in the Catalog Item.
this.my_g_form = g_form;
Note: Set Isolate Script to false.
Accessing g_form from the MRVS
Create an onLoad Catalog Client Script in the MRVS to access the global variable.
if(this.my_g_form){ g_form.setValue('to', this.my_g_form.getValue('from')); }
Example
Pre-filling a variable in the MRVS with a value from the main form.
The date selected in the “From” field in the main form is copied to the “To” field in the MRVS.
Warning: Tested in Chrome in New York. Don’t use unless strictly necessary. It might break in future releases.