- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
on 09-11-2020 04:22 PM
Removing Rows
First thought
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
- 12,098 Views

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
That's quite a workaround. Congratulations, you solved it 🙂

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Impressive, a very nice workaround! 🙂
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Nice, thank you.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi Willem,
i tried the way you did to remove all the rows, when a variable on catalog item changes. it is not working. Why? Can you help me
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
try { // try in service portal.
var field = g_form.getField("employee_info");
if (field != null) {
g_form.setValue("employee_info", JSON.stringify([]));
}
}
catch(e){ //desktop
function clearRows (sysIdMRWS) {
TableVariableService.removeAllRows(sysIdMRWS);
}
clearRows("5a80a97fdbaf9410eb9c304d3b9619e3");
}
}
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi Ansuha,
Can you log a question for this? In the question, please also share which version you are on and include screenshots.
Feel free to tag me and I will try and help! 🙂
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
I put time and effort in helping you. By removing your question, you remove any reward for the effort put into it.
Kindly consider marking my article as helpful and bookmark it in servicenow. That will be highly appreciated.
Hope you understand and thanks in advance!
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
@willem : This is was really helpful for one of my implementations. Thanks for your efforts.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Thanks for this! It is working in terms of the MRVS being cleared, however in a use case we have the MRVS is set as mandatory using
g_form.setMandatory('variable_set_1', true);
Depending on another variable on the form one of two MRVSes are displayed. When an end user switches between the options the red mandatory star turns black and the form can be submitted even though there's no data in the MRVS. It's as if the empty array is seen as an entry for the mandatory check.
I'm wondering if there is a work around for this?
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi Phonsie,
I am also having the same issue with the mvrs, is it dependant on one variable. When that variable is changed the red astrick is chnaged to black and without any records in it the form is getting submitted.
Please let me know if you find any solution to this issue.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi Sri,
Sorry, I didn't update this yet.
HI proposed a solution yesterday of looking at https://community.servicenow.com/community?id=community_question&sys_id=eea7964fdb1c9814f7fca851ca9619f6
g_form.clearValue('<MRVSvariableName>');
That solution worked better. Hopefully that will work for you also.
Kind regards,
Phonsie
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
@bbf35621 put the code in the catalog item's main Catalog Client Scripts, not in the MRVS Client Scripts. My MRVS has mandatory set via a UI Policy in the MRVS UI Policy tab. Works great as I have several MRVSs that do different things depending on the Request Type selected on the the catalog item (e.g., Add Members, Update Group Manager, Deactivate Group, etc.).
g_form.clearValue('<MRVSvariableName>');
Thanks,
Laurie
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Great job I was able to use this with On change
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi Willem,
Great article however I can’t get it to work consistently.
I have a multi row variable set in Human Resource Core application (table: sn_hr_core_case) and I tried your script and got it to work one time but in additional tests nothing happens.
My client script conditions are as following:
Table: sn_hr_core_oekonomi_finance (an CoE on sn_hr_core_case)
UI type: All
Type: onChange
Field name: State
Application: Human Resources: Core
Global=true
Script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var state = g_form.getValue("state");
if (state == 4 || state == 3 || state == 7) { // State Closed Complete, Closed Incomplete og Cancelled
{
g_form.setValue('kostordning_indmeld_afmeld', JSON.stringify([])); // 'kostordning_indmeld_afmeld' is the name of the Multi Row Variable Set
}
}
}
----
My scenario is that I want to remove the content of the multi row variable set when the state changes to one of the above as it contains sensitive personal information.
And furthermore, I would like to add an internal note to the HR-case stating that MVRS have been erased.
I’m not sure how to do this but if the primary goal is not fulfilled then that is irrelevant 😊