How to get length of MRVS row count from client script

reddy8055
Tera Contributor

Hi,

 

How can I get length of MRVS row count. I am tried using the below script to get length, I am able to get length in CMS view (alerts are showing correctly).But in Portal, I do not see any alerts if I use JSON.parse, I am able to see alerts incorrectly if i use stringify. Any help??

 

var mrvs = g_form.getValue('vta_training_details'); // internal name of your MRVS
//alert(mrvs);
var obj = JSON.parse(mrvs);
alert(obj);
var MRVSlength = obj.length;
alert(MRVSlength);

 

thanks,

8 REPLIES 8

Pavankumar_1
Mega Patron

Hi @reddy8055 ,

If my response helps you to resolve the issue close the question by Accepting solution and hit thumb icon. From Correct answers others will get benefited in future.
If not reply and share details.

If it helps please click Accept as Solution/hit the Thumb Icon.
ServiceNow Community MVP 2024.
Thanks,
Pavankumar

Pavankumar_1
Mega Patron

Hi @reddy8055 ,

If my response helps you to resolve the issue close the question by Accepting solution and hit thumb icon. From Correct answers others will get benefited in future.
If not reply and share status of the issue.

If it helps please click Accept as Solution/hit the Thumb Icon.
ServiceNow Community MVP 2024.
Thanks,
Pavankumar

Shriyansh
Tera Contributor

Hi,

 

I also have similar usecase but JSON.parse is throwing error in console. My usecase is that I want to get the count of inserted rows in mrvs and that value I need to add in a client script of mrvs for some comparisons.

 

Can someone please help me on this.

JSON.parse() will throw an error if the thing you're passing into it isn't a valid JSON string, which suggests that either you're not getting the data from your MRVS correctly (ie: make sure you're using the correct internal name when calling `.getValue()`) or your MRVS is empty and has no rows (and you're not handling this scenario). It'd be best if you shared some code and the error.