
- 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 12:03 PM
Do you want to pre-populate the MRVS when the request form, RITM, or Catalog Task loads, or after the request is submitted... Will the first row always be '2022' or the current year, then the next 4 rows are the 4 years previous?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2022 12:18 PM
The first row has to be the 'current' year, it should auto-populate to 2022 now, and then next year, it should start with 2023.
Then, yes, the following four rows should continue with the previous years (2021) and then (2020), and they can not add more than five years.
This should happen while the end-user completes the request form in the portal.
Thank you so much for your help.
- 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 04:39 PM
Hi Brad,
THANK YOU so much. I got it to work.
You ROCK.