Multi Row Variable Set: Limit Rows - ServiceNow Community
Willem
Giga Sage
Giga Sage

Limit Rows

First thought

To limit rows a quick search brought us to several sources mentioning:

var field = g_form.getField("multiple_approvers");  // multi variable set name
if (field != null) {
    field.max_rows_size = 3;  // number of rows allowed to be entered
}

This will make the 'Add'-button read only once you have reached the set limit (3 in the example above).

The problem

However, that is only working in the Service Portal/Mobile. As getField is not supported in Desktop.

To set the limit in both the Service Portal and Desktop you can use this script, which is a combination of several.

 

Solution: onLoad Catalog Client script

UI Type: All

Type: onLoad

Replace variable_set_1 with the name of your Multi Row Variable Set.

Replace the variable_set_id with the sys_id of your Multi Row Variable Set.

function onLoad() {
	try { // try in service portal.
		var field = g_form.getField("variable_set_1");
		if (field != null) {
			field.max_rows_size = 3;
		}
	}
	catch(e){ //desktop
		function setMaxRowSize (sysIdMRWS, limit) {
			var tableVariable = typeof tableVariableCache !== "undefined" &&
			tableVariableCache["table_variable_buttons_" + sysIdMRWS] != null ?
			tableVariableCache["table_variable_buttons_" + sysIdMRWS] :
			typeof table_variable !== "undefined" ? table_variable: null;
			if (tableVariable != null) {
				if (typeof tableVariable.setMaxRowSize === "function") {
					tableVariable.setMaxRowSize(String(limit));
				} else {
					tableVariable.maxRowSize = limit;
				}
			}
		}
		setMaxRowSize("variable_set_id", 3);
	}
}

The result:

After the first 2 you still see the Add button is active (left Service Portal, right back-end)

find_real_file.pngfind_real_file.png

After adding the 3th it is not active anymore

find_real_file.pngfind_real_file.png

 

Other articles on Multi Row Variable sets:

Multi Row Variable Set: Clear/Remove all values

Update value in Multi Row Variable Set (MRVS)

Comments
agarcia
Tera Contributor

Very useful, better than applying the max row property, which impacts all multi rows.

 

Thank you very much.

Anil9866
Tera Contributor

Very useful and easy to apply. It worked for me. Thanks

Version history
Last update:
‎09-15-2020 08:31 AM
Updated by: