
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2022 11:32 AM
How to dynamically set the first column to the current year (2022) and then when adding a new row to show (2021) and then the next row (2020) and so on for only five rows.
It also has to work next year so that the first row will show (2023).
Thanks
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2022 02:06 PM
This works with the caveat that I'm not certain if the Date() function always returns the value in the same format. If you get it to work for you, then it's not working for other users - due to User Preferences of time zone or date/time format - then you'll have to replace the first section with a GlideAjax call to a Script include to return the current year from the functions available on the server side for date/time manipulation.
Run this as a Catalog Client Script that Applies on a Catalog Item view only, against the Catalog Item - not within the MRVS:
function onLoad() {
var today = new Date().toString();
//alert(today); //for me this returns Thu Jun 23 2022 ...
var dteArr = today.split(' ');
var curryear =dteArr[3];
var objArr = [];
for (var i=4; i>-1; i--) {
objArr.push({year: curryear-i}); //replace 'year' with the name of the variable within the MRVS
}
g_form.setValue("mrvs1", JSON.stringify(objArr)); //replace with the internal name of the MRVS
}
To ensure that no additional rows can be added, populate the Variable Set attributes field on the MRVS with:
max_rows=5

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2022 05:07 PM
Hi MorriX
I've created a mrvs with name "mrvs" that has a field named "year" of type "single line text".
Created onLoad() script as follows.
function onLoad() {
var today = new Date();
var currYear = today.getFullYear();
var objArr = [];
for (var i = currYear; i > currYear - 4; i--) {
objArr.push({
year: i
}); //replace 'year' with the name of the variable within the MRVS
}
g_form.setValue("mrvs", JSON.stringify(objArr)); //replace with the internal name of the MRVS
}
Execution result

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-24-2022 05:02 AM
Thanks Hitoshi.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-28-2022 02:58 PM
Hi Hitoshi:
The script since to work correctly but when I try to submit the catalog I get an error message and it won't allow me to submit the request.\
Thanks

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-13-2022 01:33 PM
I am trying to remove from this MRVS the "Remove All" and the Delete "X" options. I have tried everything I found in the community, but it is not working for me. Can you please help me with some of your magic?
Thanks