Record Producer: Keep previous MRVS rows when dropdown changes, and add new rows as extra columns (o

shaikazeez
Giga Contributor

Service Catalog → Record Producer → MRVS (Multi‑Row Variable Set)

Release:
(please add your release, e.g., Vancouver/Washington)

What I’m trying to do
On a Record Producer, I have a dropdown (select box). Based on the selected option, I populate a Multi‑Row Variable Set (MRVS) using an onChange Client Script.
My requirement is:

  1. When the user changes the dropdown again, the previously inserted MRVS data must remain, and
  2. The new selection should append additional data:
    • Option A: Add the new data as additional columns to the same MRVS (if possible)
    • Option B: If columns can’t be created dynamically, then show one more MRVS and keep all MRVS rows together in the same request submission

Finally, submit everything in a single request.

What I already do

  • I populate the MRVS rows on dropdown onChange using client script (g_form) with JSON.
  • The MRVS repopulates correctly for the current selection, but when selection changes, previous rows are lost.
  • I’m looking for a clean pattern to merge previous rows with new rows and guidance on columns vs extra MRVS.

Questions

  1. What is the recommended pattern to retain previous MRVS rows and append rows for the new selection?
  2. Can MRVS columns be added dynamically at runtime? If not, what is the best design (single MRVS with superset columns + conditional show/hide, or multiple MRVS)?
  3. Best practice to merge MRVS JSON values on client side (without server round‑trip) and to load option‑specific rows via GlideAjax when needed?
  4. Any caveats for UI Policies / Catalog Client Scripts with MRVS JSON?
13 REPLIES 13

@shaikazeez 

Hope you are doing good.

Did my reply answer your question?

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

shaikazeez
Giga Contributor

Hi All,

I’ve updated the implementation so that instead of dynamically appending columns, I’m now populating the MRVS based on the dropdown selection.
I created an onChange client script on the dropdown field, and based on the selected value, the respective fields (Functional Guidance / Cost Center) are shown or hidden accordingly.

var function_guide = g_form.getValue('functional_guidance');
var cost_center = g_form.getValue('cost_center');

 

if (newValue == 'Functional Guidance') {
    g_form.setDisplay('functional_guidance', true);
    if (cost_center) {
        g_form.setDisplay('cost_center', true);
    } else {
        g_form.setDisplay('cost_center', false);
    }
} else if (newValue == 'Cost Center') {
    g_form.setDisplay('cost_center', true);
    if (function_guide) {
        g_form.setDisplay('functional_guidance', true);
    } else {
        g_form.setDisplay('functional_guidance', false);
    }
}



The words you are using are not correct, and do not make any sense in the context of a MRVS.  There is zero chance this script is affecting the variables in a MRVS that is shown on a catalog item request form.  Show screenshots of what you are talking about, or close the thread if you don't have a question.

stevemarkovick
Tera Contributor

Tried solving something similar and it got messy pretty fast once the dropdown kept reloading the MRVS. What worked for me was storing the existing rows in a client-side object before the change, then merging them back after repopulating instead of overwriting everything. Also helped to control updates with a flag to avoid multiple triggers. This kind of logic feels unavoidable with MRVS sometimes