How to get length of MRVS row count from client script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-16-2022 03:32 PM
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,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-16-2022 09:07 PM
@reddy8055 On client script "UI Type" field might be set to Desktop please change it to All. That should fix the issue.
Please mark as correct answer if this solves your issue.
ServiceNow Community Rising Star, Class of 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-16-2022 11:12 PM
Hi @reddy8055 ,
refer below question it will helps you.
https://www.servicenow.com/community/developer-forum/get-mrvs-row-count-onsubmit/m-p/1545351
ServiceNow Community MVP 2024.
Thanks,
Pavankumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2022 02:11 AM - edited 12-17-2022 02:20 AM
Hi @reddy8055 ,
Try to use
A MVRS is literally stored as JSON. You can parse the JSON and get it's length.
e.g.
g_form.getValue('questions'); returns below /* "[ { \"order\":\"100\", \"question\":\"What do you need help with?\", \"required\":\"Yes\", \"help_text\":\"\" } ]" */
So with that... you can literally just say run a script like so;
var mvrsValue = g_form.getValue('questions'); if(mvrsValue){//if it has a value var jsonObj = JSON.parse(mvrsValue); console.log('There are ' + jsonObj.length + ' rows); } else { // if i recall correctly, .getValue returns null if empty console.log('No Rows'); }
Check the below links for more details:
https://www.servicenow.com/community/developer-blog/json-parsing/ba-p/2279166
Regards,
Reshma
**Please mark my answer correct or helpful based on the impact**
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-18-2022 08:59 PM
Hi @reddy8055 ,
If my response helped you to resolved the issue then close the question by Accepting solution and hit thumb icon. From Correct answers others will get benefited in future.
ServiceNow Community MVP 2024.
Thanks,
Pavankumar