ServiceNow Widget Debugging: Temporarily Set Any Field Value (Without Touching Code)
Let’s be honest… Service Portal debugging is slow. Every small change = 👉 Update script 👉 Save 👉 Reload 👉 Navigate back 👉 Test again Repeat that 10 time...
If you’ve worked with Multi-Row Variable Sets (MRVS) in ServiceNow, you’ve probably seen this requirement come up:
“Allow users to add rows sometimes… but restrict them in certain scenarios.”
This is where most people go down the wrong path like DOM manipulation, hiding buttons, messy client scripts…
But there’s actually a clean, controlled way to do this using max_rows_size dynamically.
Let’s get into it.
Not just:
But:
Instead of hardcoding Maximum rows in the MRVS record, we control it dynamically using a Catalog Client Script (onLoad).
function onLoad() {
var mrvs = g_form.getField('your_mrvs_name');
if (!mrvs) return;
if (yourCondition()) {
mrvs.max_rows_size = 0; // disables Add
} else {
mrvs.max_rows_size = 5; // or whatever limit you want
}
}g_form.getField('your_mrvs_name')max_rows_size = 0max_rows_size = 5👉 So instead of static configuration, you now have full runtime control
This is where things get interesting.
You can base it on:
No:
querySelector👉 Which means:
Once you understand this, you can apply it to:
your_mrvs_nameUse the exact variable name, not the label.
yourCondition()This is where your logic lives. Example:
function yourCondition() {
return g_form.getValue('request_type') == 'view_only';
}
Even when disabled:
If data is inserted via:
It will still work.
👉 This only controls user interaction
In one of my implementations:
Instead of rebuilding UI logic, we simply did:
if (stage == 'approval') {
mrvs.max_rows_size = 0;
}Clean. Predictable. No surprises.
I’ve seen people:
All of these:
👉 If max_rows_size solves it, don’t overthink it.
This is one of those small tricks that makes your implementation feel clean.
Instead of fighting the platform, use what it already gives you.
Written by
Let’s be honest… Service Portal debugging is slow. Every small change = 👉 Update script 👉 Save 👉 Reload 👉 Navigate back 👉 Test again Repeat that 10 time...
Learn how to embed the ServiceNow Virtual Agent in any website using the Portable Web Client, with support for SSO, CORS, and custom branding. Includes code sam...
💡Specific record operations? GlideRecord Aggregated data and calculations? GlideAggregate If you're anything like me you must have spent a fairbit of time s...