Set a limit on a date variable to end of current year

phaug
Tera Contributor

I have a requirement on a catalog item to restrict the date variable a person can select to be the last day of the current year. I'm guessing I'll need to write a client script but I'm not sure exactly how to go about checking that it's the end of the current calendar year. Any suggestions are appreciated.

1 ACCEPTED SOLUTION

Saloni Suthar
Mega Sage
Mega Sage

Hi @phaug ,

 

It is easily doable using UI Policies. Please review the community article - https://www.servicenow.com/community/developer-articles/no-code-date-validations-through-catalog-ui-....

 


If my response helped you, please click on "Accept as solution" and mark it as helpful.
- Saloni

View solution in original post

3 REPLIES 3

Saloni Suthar
Mega Sage
Mega Sage

Hi @phaug ,

 

It is easily doable using UI Policies. Please review the community article - https://www.servicenow.com/community/developer-articles/no-code-date-validations-through-catalog-ui-....

 


If my response helped you, please click on "Accept as solution" and mark it as helpful.
- Saloni

Thanks, that worked. It allowed me to set it dynamically so I don't have to update it every year.

Anubhav24
Mega Sage
Mega Sage

Hi @phaug ,

You can try this method :

var gdt1 = new GlideDateTime("2024-12-31 23:59:59");
var gdt2 = new GlideDateTime("2017-06-12 15:11:12");
gs.info(gdt1.onOrAfter(gdt2));
Or 
You can check
getYearNoTZ() : this returns the year and extract the year form the current date to see if it greater than the current year and return the error to the user.
 
Please mark helpful/correct if my response helped you.