top of page

Experiencing challenges with ServiceNow support?

Access professional, reliable assistance tailored to your needs—without breaking your budget.

Making ServiceNow Catalog Items Dynamic: Triggering Actions When Multi-Row Variable Sets Change

Updated: Mar 29

For ServiceNow users leveraging the Service Catalog, Multi-Row Variable Sets (MRVS) are a powerful feature for capturing multiple instances of related information within a single catalog item. Imagine needing to order multiple items, each with its own specifications, or list attendees for an event. MRVS makes this straightforward. However, a common challenge arises when you need to trigger actions on the main catalog item itself based on changes happening within the MRVS, such as when a new row is added. This article will guide you through a clever solution to achieve this, enabling dynamic updates and enhanced user experience within your ServiceNow Service Catalog.


The initial hurdle many ServiceNow developers face is the lack of a direct event trigger on the catalog item when a new row is added to an MRVS. Standard client scripts associated with the MRVS operate within the scope of that variable set and cannot directly manipulate variables on the parent catalog item in real-time upon row addition.

Consider a scenario where you have a catalog item for ordering computer peripherals. Within this item, you have an MRVS allowing users to specify multiple peripherals, each with a "Cost Per Item." Your requirement is to automatically calculate and display the "Total Cost" of all selected peripherals on the main catalog item as users add or remove rows in the MRVS.


Here’s a verified method to achieve this dynamic interaction:


The Two-Script Approach Using a Trigger Variable

This solution involves a two-pronged approach utilizing two client scripts and an intermediary "trigger" variable on your catalog item.


Step 1: Create a Trigger Variable on Your Catalog Item

First, you'll need to create a new variable on your main catalog item. This variable will act as a flag to initiate the calculation. A simple "Yes/No" type variable named something like trigger_calculation (with the default value set to "No" or "false") will work perfectly. This variable will not be directly visible to the user.


Step 2: Implement an onChange Client Script on a Field within the MRVS

Next, create an onChange client script that is associated with your Multi-Row Variable Set. This script will be triggered whenever a value changes within any of the fields in a row of the MRVS. For this example, you can choose a relevant field like the "Cost Per Item" field or even a hidden field if you have one.

Here’s the code for this client script:

JavaScript

function onChange(control, oldValue, newValue, isLoading) {
  if (isLoading || newValue === '') {
    return;
  }
  if (parent.g_form) {
    parent.g_form.setValue('trigger_calculation', true);
  }
}
  • Explanation: This script checks if the form is loading or if the new value is empty. If not, it uses parent.g_form to access the GlideForm object of the parent catalog item and sets the value of our newly created trigger_calculation variable to true. This action will trigger the next client script.


Step 3: Implement an onChange Client Script on the Trigger Variable of the Catalog Item

Now, create another onChange client script, but this time associate it with the trigger_calculation variable you created in Step 1 on the main catalog item. This script will perform the actual calculation.

Here’s the code for this client script:

JavaScript

function onChange(control, oldValue, newValue, isLoading) {
  if (isLoading || newValue == '' || newValue == 'false') {
    return;
  }

  // Get the MRVS data in JSON format
  var multiRowVariableSet = JSON.parse(g_form.getValue('your_mrvs_variable_name')); // Replace 'your_mrvs_variable_name' with the actual name of your MRVS variable

  var totalCost = 0;
  for (var i = 0; i < multiRowVariableSet.length; i++) {
    totalCost += parseFloat(multiRowVariableSet[i].cost_per_item_variable_name); // Replace 'cost_per_item_variable_name' with the actual name of your "Cost Per Item" variable in the MRVS
  }

  g_form.setValue('total_cost_variable_name', totalCost); // Replace 'total_cost_variable_name' with the actual name of your "Total Cost" variable on the catalog item
  g_form.setValue('trigger_calculation', false); // Reset the trigger
}
  • Explanation: This script first checks if the form is loading, the new value is empty, or if the trigger is set back to false. If none of these conditions are met (meaning the trigger has been set to true), it proceeds with the calculation.

  • It retrieves the data from your Multi-Row Variable Set using g_form.getValue() and parses it from JSON format. Make sure to replace 'your_mrvs_variable_name' with the actual internal name of your MRVS variable.

  • The script then iterates through each row in the multiRowVariableSet and adds the value from the "Cost Per Item" variable (replace 'cost_per_item_variable_name' with its actual name) to the totalCost. It's important to use parseFloat() to ensure accurate calculation if the cost is a decimal value.

  • Finally, it sets the value of the "Total Cost" variable on the main catalog item (replace 'total_cost_variable_name' with its actual name) to the calculated totalCost and then resets the trigger_calculation variable back to false to be ready for the next change.


Practical Use Case

This approach is highly versatile. Beyond calculating totals, you can adapt this method to:

  • Update a summary field on the catalog item based on selections within the MRVS.

  • Show or hide other variables on the catalog item based on the number of rows in the MRVS or the values within those rows.

  • Perform data validation across multiple rows in the MRVS and display feedback on the catalog item.


Alternative Considerations

While the two-script approach is effective, another less ideal but sometimes considered alternative involves using an onLoad client script with setInterval to periodically check for changes in the MRVS and recalculate the total. However, this method can be less efficient and might not provide a truly real-time update feel, potentially impacting performance. It's generally recommended to use event-driven approaches like the one described above whenever possible.


Conclusion

Dynamically updating information on a ServiceNow catalog item based on changes within a Multi-Row Variable Set enhances the user experience and allows for more sophisticated catalog item designs. By employing the clever technique of using a trigger variable and two strategically placed onChange client scripts, you can seamlessly bridge the gap between the MRVS and the parent catalog item, enabling real-time calculations and other dynamic behaviors. This method empowers you to create more interactive and user-friendly service catalog offerings. Take the next step to implement this solution in your ServiceNow instance and unlock the full potential of your catalog items.

Experiencing challenges with ServiceNow support?

Access professional, reliable assistance tailored to your needs—without breaking your budget.

CONTACT

New Zealand HQ

Integrated Knowledge Consulting Office

Level 3, 93 Grafton Road

Auckland

South Korea

Integrated Knowledge Consulting Office

BMY역삼타워 6층

서울특별시 강남구 역삼동 678-10번지

 

info@ikconsulting.com

Thanks for submitting!

  • LinkedIn Social Icon

© Copyright 2025 Integrated Knowledge Consulting. All rights reserved.

bottom of page