How to count the records added in Multi Row Variable set(MRVS) dynamically

RiyazAhamed
Tera Contributor

I need to display the count of the records submitted in MRVS.

find_real_file.png

As of above image, the Total Number of USers in Request should be 1, it should be dynamically change when ever new record is added in MRVS or remove existing record from MRVS.

any help would be appreciated.

Thanks

1 ACCEPTED SOLUTION

Geoff_T
Mega Sage

Hi, 

If it's an option to simply grab the count on submit you could use the following onSubmit script applied to the catalog item:

var mrvsStr = g_form.getValue("mrvs_name");
var mrvsData = JSON.parse(mrvsStr).length;
g_form.setValue("Count", mrvsData);

 

 

I also experimented updating the count dynamically like you mention each time a row is added. This onSubmit script works fine when applied to the MRVS itself:

var mrvsStr = parent.g_form.getValue("mrvs_name");
var mrvsData = JSON.parse(mrvsStr).length;
parent.g_form.setValue("Count", mrvsData + 1);

The issue now with this scenario is how to update the count when you remove a row or remove all. I see a few suggestions like the following:

https://community.servicenow.com/community?id=community_question&sys_id=8a612681db8d64103daa1ea66896190a

 

I guess you could experiment further to see if this works for you.

 

Geoff

View solution in original post

1 REPLY 1

Geoff_T
Mega Sage

Hi, 

If it's an option to simply grab the count on submit you could use the following onSubmit script applied to the catalog item:

var mrvsStr = g_form.getValue("mrvs_name");
var mrvsData = JSON.parse(mrvsStr).length;
g_form.setValue("Count", mrvsData);

 

 

I also experimented updating the count dynamically like you mention each time a row is added. This onSubmit script works fine when applied to the MRVS itself:

var mrvsStr = parent.g_form.getValue("mrvs_name");
var mrvsData = JSON.parse(mrvsStr).length;
parent.g_form.setValue("Count", mrvsData + 1);

The issue now with this scenario is how to update the count when you remove a row or remove all. I see a few suggestions like the following:

https://community.servicenow.com/community?id=community_question&sys_id=8a612681db8d64103daa1ea66896190a

 

I guess you could experiment further to see if this works for you.

 

Geoff