- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2024 07:21 AM
good morning everyone,
so i have a trick request to configure,
i have an MRV with a reference variables that is looking up on the cmn_department table
i want to have the ability to auto fill the other row users will select with the same value they selected in the first row of the MRV.
Example:
the Department Column u selected Office Expenses
i want every other row to only show Office Expenses and not have the users be able to select anything else but Office Expenses base on their first row
so all other rows will only have the Office Expense and nothing else
is this possible with an onChange script?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-08-2024 08:07 AM
Consider having Department variable outside of your mrvs in the form as well.. After the user selects this form Department variable and is adding first mrvs row, use onLoad script within mrvs to set the read-only mrvs Department field using below script:

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-08-2024 08:02 AM
What did not work about it? Did it not save the value? Did it not set the value?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-08-2024 08:43 AM
I found that part of @maroon_byte suggestion will work probably better for what I suggested.
You can use g_service_catalog.parent.getValue("MRV_NAME") to get the value of the MRV and it will be in JSON format.
So you can just use JSON.parse to turn it into an object, check to see if there is at least one row in it and if it is then use the value for the department to set the var on the popup when it opens using the same basic idea that I posted for the onLoad.
//In an onLoad script for the MRV
var mrv = JSON.parse(g_service_catalog.parent.getValue("MRV_NAME"));
if(mrv && mrv[0] && mrv[0].NAME_OF_DEPARTMENT_VAR_IN_MRV) {
g_form.setValue("department", mrv[0].NAME_OF_DEPARTMENT_VAR_IN_MRV);
g_form.setReadOnly("department", true);
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-08-2024 08:51 AM
Here is some better code and this one I did test with one of our MRV's and it worked for me.
var field = "NAME_OF_DEPARTMENT_FIELD_IN_MRV";
var mrvVal = g_service_catalog.parent.getValue("international_travel_request");
if(mrvVal) {
var mrv = JSON.parse(g_service_catalog.parent.getValue("NAME_OF_MRV"));
if(mrv && mrv[0] && mrv[0][field]) {
g_form.setValue(field, mrv[0][field]);
g_form.setReadOnly(field, true);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-08-2024 08:52 AM
He needs to set Department in all rows the same... so no need to set the Department in first row only.
If don't want to have Department in the form, another option is to use browser's Local/Session storage in client scripts to set and retrieve values. I feel, its bit flaky and tedious to develop/maintain and it wont work in Incognito mode.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-08-2024 08:57 AM
I was simply showing how to set the value in all rows to what the first one has. But you do make a good point. Why even have the department as a question in the MRV if every row is going to have the same value. Move it outside the MRV as a question on the cat item and then the user just sets it one time. No need to do anything else and that simplifies it.