- 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 11:25 AM
Hello @booher04 ,
I saw that you have marked my answer as correct. Were you able to figure it out or do you still need assistance?
Regards,
Robert
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-14-2025 11:27 AM
Yes, error on my part on when to run the script. I had it to run on RITM and NOT SCTASK. Once I switched that, it worked perfect. Thank you!