onLoad catalog client script Remove choice from Select box based on date/time variable

booher04
Tera Guru

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). 

I tried the below with no success:
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');
}
}
1 ACCEPTED SOLUTION

Robert H
Mega Sage

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

View solution in original post

6 REPLIES 6

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

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!