MRVs to Another MRVS
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-30-2024 08:44 AM
Hello, I've been tasked with mapping values from one MRSV to another within the same form. MRVS 2 holds some of the same values as MRVS 1.
The below code has been suggested and modified but it is not mapping the values from MRVS 1 to the same value in MRVS 2.
below is the code:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-30-2024 09:57 AM
Hi Ryan,
Do you need / want to see the second MRVS populate on the form, or can this be done after the request/RITM/Catalog Task is submitted or updated? If it needs to be on the form before a save/reload, what is the trigger - on load, or when something changes? Does the second MRVS contain variables with the same names and / or types as the first MRVS?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-30-2024 10:04 AM
This would need to be done as soon as the first MRVS is populated. The trigger would be an onChange. And yes the Second MRVS contains some of the same values as the first
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-30-2024 11:14 AM
The Catalog Item has access to a variable containing the contents of the MRVS that is set/updated when a row is added or edited, but it's tricky to trigger when this changes. There are some posts on the topic you can explore, but in this case you could just trigger this with an onSubmit Catalog Client Script that applies to the (first) MRVS. This script would add data from the row that is about to be added in the first MRVS to the second MRVS.
In this example I have a MRVS with the internal name employees_mrvs that I am adding rows to on a request form. It has a reference variable to the sys_user table named v_employee_mrvs and a Select Box named v_choice_mrvs. When a row is added to this MRVS, I will add a row to a MRVS named managers_mrvs, populating a variable in this MRVS named v_manager_mrvs that is also a reference to the sys_user table. This MRVS does not have a variable for the select box, and does have a single line text variable that will remain unpopulated, or you can populate it with something in the script.
function onSubmit() {
var mrvsArr = [];
var mrvs2 = g_service_catalog.parent.getValue('managers_mrvs');
if (mrvs2.length>0) {
mrvsArr = JSON.parse(mrvs2);
}
mrvsArr.push({
"v_manager_mrvs" : g_form.getValue('v_employee_mrvs') //add a comma then a row for each variable to populate
});
if (this) { //Service Portal method
this.cat_g_form.setValue('managers_mrvs', JSON.stringify(mrvsArr));
} else { //native UI method
parent.g_form.setValue('managers_mrvs', JSON.stringify(mrvsArr));
}
}
If you are using Service Portal you will also need this onLoad Catalog Client Script that applies to the Catalog Item, not the MRVS
function onLoad() {
if (this) {//we only need to do this for Service Portal
//We need to make the g_form object for the parent item available from the MRVS window
this.cat_g_form = g_form;
}
}
Once you get this working consider what will happen when a row in the first MRVS is being edited - as it is right now, a new row will be added with the new information, but if there's a variable in the first MRVS that can't or won't change once added, or depending if you are using the native UI vs Service Portal we may be able to detect an edit vs add...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-15-2025 07:02 PM - edited 03-15-2025 08:42 PM
x