- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-07-2023 10:13 AM
Hello, i have the requirement for a new variable called 'calendar' on my Catalog Item, to only show years from now on.
You should be able to select only one year, it can be this actual year or an upcoming one.
How can i achieve this?
Thank you.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-08-2023 05:26 AM
This should work well for you. The 'calendar' variable will be a Select Box type. Choice table = -- None -- and the Include none box checked (if that's what you prefer). That's it for the variable setup - you will not create any Question Choices. Next create an onLoad Catalog Client Script that Applies on a Catalog Item view, Requested Items, and/or Catalog Tasks - where ever this variable will be populated/updated. Your script would look something like this to populate the Calendar select box with choices for the current year and the next 24 years:
function onLoad() {
var today_date = formatDate(new Date(), 'yyyymmdd').substring(0,4);
for(var i=0; i<25; i++) {
g_form.addOption('calendar', parseInt(today_date) + i, parseInt(today_date) + i);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-07-2023 12:29 PM
Hi Olga!
One way to do this is with a Lookup Select Box type variable. Reference the sys_choice table, or anywhere else that you have or want to create a record for each year as far out as you want to be selected. If you're not keen to update this table at the beginning of each year to make the previous year record inactive, you can call a Script Include in the Reference qualifier of the Lookup Select Box. The Script Include will get the current year, then only return records from the choice table that are this number or higher.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-08-2023 03:12 AM
Hi Brad, thank you for your response.
I should create the variable so that i can only choose upcoming years and not see the past ones, it should be dynamic so that you should not have to update the years. Mentioning that i do not have years as choices to refere to.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-08-2023 05:26 AM
This should work well for you. The 'calendar' variable will be a Select Box type. Choice table = -- None -- and the Include none box checked (if that's what you prefer). That's it for the variable setup - you will not create any Question Choices. Next create an onLoad Catalog Client Script that Applies on a Catalog Item view, Requested Items, and/or Catalog Tasks - where ever this variable will be populated/updated. Your script would look something like this to populate the Calendar select box with choices for the current year and the next 24 years:
function onLoad() {
var today_date = formatDate(new Date(), 'yyyymmdd').substring(0,4);
for(var i=0; i<25; i++) {
g_form.addOption('calendar', parseInt(today_date) + i, parseInt(today_date) + i);
}
}