create or update record in multi row question answer for MRVS
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-21-2020 08:19 AM
Hi Everyone,
In HR module, we have a resubmit the function of the case, the form includes multi-row variable set, after the business scenario is when the case was reject, the user can go to the portal page to modify the contents of the case.
However, the problem i encounter now is how do i deal with the data in the background if the user adds or removes a row of multi-row. I know their corresponding content is stored in multi row question answer, and how to modify or create the corresponding value in multi row question answers after getting the new multi rows on the form, but now i have no idea, can someone give me some advice? Many thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-21-2020 08:21 AM
Hi,
how are users adding or removing the rows of MRVS variable?
Also what exactly is required when row is being added or deleted?
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-21-2020 08:34 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-21-2020 09:44 AM
Hi,
You can do like this.
- Create a Dummy Variable in your HR Catalog. Probably take a Multi Line Text Variable.
- Create a UI Policy to hide the above variable on all views. Uncheck the "Visible on Summaries"
- Create an Onload Script and capture the existing values like this.
var existingval = [{"name":"narsing"}, {"name": "narsing123"}]; //This is not needed in your case. It will be like [var existingval = JSON.parse(g_form.getValue("mrvs")];
var arr = [];
for(var m = 0; m < existingval.length; m++) {
var n = {"rownum": m, "name": existingval[m].name};
arr.push(n);
}
var filler = arr;
g_form.setValue('mrvs_test', JSON.stringify(filler)); //Setting the MRVS value into a Dummary variable.
Now, Create OnSubmit Client Script like this.
var submitvals = JSON.parse(g_form.getValue('mrvs'));
var prevvals = JSON.parse(g_form.getValue('mrvs_test'));
if(submitvals.length > prevvals.length) {
alert("Added new rows");
return false;
}
if(prevvals.length > submitvals.length ) {
alert("removed rows");
return false;
}
for(var m = 0; m < submitvals.length; m++) {
if(submitvals[m].name != prevvals[m].name) {
alert('Previous value for Row ' + (m+1) + ' is ' + prevvals[m].name + '. But current value is ' + submitvals[m].name);
return false;
}
}
Sample#
Onload the Page will be like this
Now, I am going to change the value for the 1st Row.
When I submit the Request, I can see an alert like this
You may modify the script according to your needs. But basically you can read the MRVS values as mentioned above.
Please mark it as correct answer if it helps.
Thanks,
Narsing
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-21-2020 10:42 PM
Hi,
I want to add or delete data to Multi Row Question Answers, but I use row.addrow () and row.deleterow (), which is the related document link,https://docs.servicenow.com/bundle/paris-application-development/page/script/server-scripting/concept/c_ScriptableServiceCatalogVariables.html, do you know how to operate?