Multi Row Variable Set: Clear/Remove all values
This one started of Easy as well. Setting the Multi Row Variable Set to an empty array will clear all values. We noticed that adding the JSON.stringify resulted in the Row count being available.
g_form.setValue('variable_set_1', JSON.stringify([]));
The problem
However, this cleared the values, but if we had already reached the Row Limit of the previous requirement, the 'add'-button had been set read only. Clearing the values this way did not make the 'add'-button available.
To do this, both in Service Portal and Desktop, use the following script.
Solution: onChange 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 onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
try { // try in service portal.
var field = g_form.getField("variable_set_1");
if (field != null) {
g_form.setValue('variable_set_1', JSON.stringify([]));
field.max_rows_size = 3;
}
}
catch(e){ //desktop
function clearRows (sysIdMRWS) {
TableVariableService.removeAllRows(sysIdMRWS);
}
clearRows("variable_set_id");
}
}
The result:
Other articles on Multi Row Variable sets:
Update value in Multi Row Variable Set (MRVS)
Multi Row Variable Set: Limit Rows
Resources:
https://swethabussa.blogspot.com/2019/07/multi-variable-set-servicenow.html
https://www.servicenow.com/community/developer-articles/multi-row-variable-set-clear-remove-all-values/ta-p/2297910