- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-14-2025 08:44 AM
Trying to remove a choice from a select box variable based on a date/time variable being on or after the first day of the year(ex: January 1, 2025).
I need to remove the choice "CommVault" from the select box variable "data_restore_environment" if the date/time variable "restore_date" is on or after the first day of this year(January 1, 2025).
function onLoad() {
var presentYear = new GlideDateTime().getYear();
var yearStart = new GlideDateTime(presentYear + '-01-01 00:00:00');
var dre = new GlideDateTime(g_form.getValue('restore_date'));
if (dre >= yearStart) {
g_form.removeOption('data_restore_environment', 'CommVault');
alert('TEST');
}
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-14-2025 09:08 AM - edited 04-14-2025 09:38 AM
Hello @booher04 ,
GlideDateTime() is a server side API and not available in Client Scripts.
Please replace your script with the following:
function onLoad() {
var restoreDate = getDateFromFormat(
g_form.getValue('restore_date'), g_user_date_time_format);
var currentYear = new Date().getUTCFullYear();
var beginningOfThisYear = new Date(currentYear, 0, 1).getTime();
if (restoreDate >= beginningOfThisYear) {
g_sc_form.removeOption('data_restore_environment', 'CommVault');
}
}
Please make sure the "Applies on Catalog Tasks" checkbox is enabled.
Regards,
Robert
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-14-2025 09:08 AM - edited 04-14-2025 09:38 AM
Hello @booher04 ,
GlideDateTime() is a server side API and not available in Client Scripts.
Please replace your script with the following:
function onLoad() {
var restoreDate = getDateFromFormat(
g_form.getValue('restore_date'), g_user_date_time_format);
var currentYear = new Date().getUTCFullYear();
var beginningOfThisYear = new Date(currentYear, 0, 1).getTime();
if (restoreDate >= beginningOfThisYear) {
g_sc_form.removeOption('data_restore_environment', 'CommVault');
}
}
Please make sure the "Applies on Catalog Tasks" checkbox is enabled.
Regards,
Robert
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-14-2025 09:18 AM
Thanks for the reply! The variable "data_restore_environment" only appears on SCTASKs, and the date/time variable "restore_date" is selected on the Portal when the user submits the item. It won't change after submission.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-14-2025 09:40 AM
Hello @booher04 ,
Thanks for the feedback, that's important information.
I have adjusted the script in my original response to work for Catalog Tasks.
Regards,
Robert
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-14-2025 11:08 AM
@Robert H thanks for the quick response. I tried the script you provided. It doesn't seem to be working either. The choice is still displaying on the SCTASK for the select box variable "data_restore_environment".