Only allow the first of a month as valid date selection.

Scott Gibbons
Tera Contributor

Dear Community,

I want to restrict the user to be only able to select the 1st of a month with the variable type DATE .

For clarity, this means the user cannot select any other date within September other than September 1st.

I am also open to other suggestions like being able to select another date but the field defaults to the 1st of the month (with a fitting UI message of course.).

Thanks in advance,

Scott

 

4 REPLIES 4

Muhammad Khan
Mega Sage

@Scott Gibbons 

Use onChange() Client Script with GlideAjax on your date restrict the value in date field.

Try this in the background script.

var gd = new GlideDate();
gs.info(gd.getDayOfMonthNoTZ());

if(gd.getDayOfMonthNoTZ() > 1)
    gs.print('Only 1st date of month is allowed.');
else
    gs.print('Date is correct.');

For Scoped Application, see the below image for reference.

find_real_file.png

For Global Scope Applicationsee the below image for reference.

find_real_file.png

Kalyani Jangam1
Mega Sage

Calculate first date of current month

var gdt = new GlideDateTime();
var dt= gs.beginningOfThisMonth(gdt);
gs.print(dt);

Maik Skoddow
Tera Patron
Tera Patron

Hi

in my opinion it is a bad user experience if the user is allowed to select only one day and it also causes some efforts which have the touch of a workaround.

Why don't you offer the user a selection of month names and set the date internally to the first day of the selected month? This makes more sense to me from the user's perspective.

Maik

Totally with you and the proposal of an alternative to the calendar had already been posed to the PO. Here exploring my options though.

Thanks for the input. Much appreciated.