mvrs : Need to count number of rows
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-26-2020 06:08 AM
I have a catalog item with a multiple row variable set.
I would like to display (in another field of the form), information related to mvrs data
For example, number of rows.
I tried with onSubmit catalog script on mvrs but found that this kind of script can't access variables outside mvrs.
Do you have any idea ?
- Labels:
-
User Interface (UI)

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-26-2020 08:51 AM
Hi,
Try Below,
OnSubmit() Client Script
var length = '';
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);
length = jsonObj.length;
} else { // if i recall correctly, .getValue returns null if empty
console.log('No Rows');
length = jsonObj.length;
}
//CALL Script Include to Store Length in Another table
var ga = new GlideAjax('StoreDetails');//this is the script include
ga.addParam("sysparm_name", "storeLength"); //this is the function within the script include
ga.addParam("sysparm_length",length);
ga.getXML(callback);
function callback(response)
{
var answer = response.responseXML.DocumentElement.getAttribute("answer");
alert(answer);
}
}
Script Include to store length to another table
var StoreDetails = Class.create();
StoreDetails.prototype = {
storeLength : function() {
var length = this.getParameter('sysparm_length');
var gr = new GlideRecord('your table name');
gr.addActiveQuery();
gr.query();
if(gr.next())
{
gs.addInfoMessage("length=" +length);
gr.field_name = length;
gr.update();
}
},
type: 'getStandardFields'
};
Please mark correct/helpful answer if it help you in any way.
Thanks,
Kunal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-29-2020 01:39 AM
Hi,
Thank you very much for your answer. It really helps.
I also need to display this count in the cat item form.
Is there a way (in client side)
- to 'see' modification of length in a record of 'my table name'
- then retrieve this value
- and display in form

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-29-2020 05:03 AM
Hi,
Updated script:
OnSubmit() Client script:
var length = '';
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);
length = jsonObj.length;
} else { // if i recall correctly, .getValue returns null if empty
console.log('No Rows');
length = jsonObj.length;
}
//CALL Script Include to Store Length in Another table
var ga = new GlideAjax('StoreDetails');//this is the script include
ga.addParam("sysparm_name", "storeLength"); //this is the function within the script include
ga.addParam("sysparm_length",length);
ga.getXML(callback);
function callback(response)
{
var answer = response.responseXML.DocumentElement.getAttribute("answer");
alert(answer); //this will show length
}
}
Script Include:
var StoreDetails = Class.create();
StoreDetails.prototype = {
storeLength : function() {
var length = this.getParameter('sysparm_length');
var gr = new GlideRecord('your table name');
gr.addActiveQuery();
gr.query();
if(gr.next())
{
gs.addInfoMessage("length=" +length);
gr.field_name = length;
gr.update();
// Add this line
return gr.field_name; //Pass this length to client script
}
},
type: 'getStandardFields'
};
Thanks,
Kunal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-29-2020 05:16 AM
In callback function, you may display count with alert
But I need to put this value in a specific field
And g_form("my_field',count) won't work because 'my_field' is not inside mrvs
We may create an action button/action or select zone in the form to read count in table and put it in the field but this is not user friendly (End user need to do something to read value)

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-26-2020 10:37 AM
Hi
If you want to access the data that is outside of MRVS into the variable set, then refer to this link.
Mark the comment as a correct answer and helpful if it helps.