How to get rowCount of mrvs and set the value of a field in Catalog item variable.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-26-2023 06:34 AM
Hi,
I have MRVS if I add a row , it should take few MRVS variable values and set the values in the single line text variable on the catalog item and If i remove the row it will also remove the text form the catalog item variable.
Note:- row_size =1; //the row size is set to be not more than 1
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-26-2023 06:41 AM
you can use below link and detect when new row was added/removed and based on that update the other variable
MRVS detect when a row is removed or deleted
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-26-2023 06:52 AM
How will I get to know the row is added or deleted.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-26-2023 06:54 AM
that's what is shared in the above link which I mentioned.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-26-2023 06:59 AM
HI @jitusingh ,
I trust you are doing fine.
To achieve the functionality you described, you can use client-side scripting in the catalog item's variable set. Here's an example of how you can accomplish this:
- Create a multi-row variable set (MRVS) with the desired variables.
- Add a "OnLoad" client script to the catalog item form to initialize the behavior.
- Add a "OnChange" client script to the MRVS variable to update the single line text variable whenever a row is added or removed.
function onLoad() {
// Disable MRVS if row size is more than 1
var mrvsVariable = g_form.getVariable('<variable_name>'); // Replace <variable_name> with the actual MRVS variable name
if (mrvsVariable.getRowCount() > 1) {
mrvsVariable.setDisabled(true);
}
}
OnChange script (for the MRVS variable):
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue === '') {
return;
}
var textVariable = g_form.getControl('<text_variable_name>'); // Replace <text_variable_name> with the actual single line text variable name
if (control.getRowCount() > 0) {
var firstRow = control.getRow(0);
var value1 = firstRow.<variable_name1>; // Replace <variable_name1> with the actual MRVS variable name
var value2 = firstRow.<variable_name2>; // Replace <variable_name2> with another MRVS variable name if needed
// Set the values in the single line text variable
textVariable.value = value1 + ' ' + value2; // Modify this line based on your desired logic
} else {
// Remove the text from the single line text variable
textVariable.value = '';
}
}
Was this answer helpful?
Please consider marking it correct or helpful.
Your feedback helps us improve!
Thank you!
Regards,
Amit Gujrathi