How to set a current year to the Service catalog variable

ragz
Tera Expert

Hi

How to set a current year to single line text variable in service catalog  ?

javascript:gs.now() is returning 07-31-2019 . But I need only current year 2019 .

1 ACCEPTED SOLUTION

Jaspal Singh
Mega Patron
Mega Patron

Hi,

 

Try using javascript: var gdt = new GlideDateTime(gs.nowDateTime());gdt.getYear();

 

Thanks,

Jaspal Singh

 

Hit Helpful or Correct on the impact of response.

 

View solution in original post

5 REPLIES 5

Elijah Aromola
Mega Sage

Try: gs.now().getByFormat(ā€˜yyyy’);

Please mark as correct/helpful if this answered your question!

Not working , gs.now().getByFormat(ā€˜yyyy’);  returning empty value .

Jaspal Singh
Mega Patron
Mega Patron

Hi,

 

Try using javascript: var gdt = new GlideDateTime(gs.nowDateTime());gdt.getYear();

 

Thanks,

Jaspal Singh

 

Hit Helpful or Correct on the impact of response.

 

I am trying to use this as the default value for my "Process Year" variable in my Catalog Item, but I am getting an error message, presumably because I am trying to do this in a scoped application.

 

The exact error message is:

 

Function nowDateTime is not allowed in scope XXXXXXXXXX. 
Use GlideDateTime instead: new GlideDateTime().getDisplayValue()

 

How can I get this to work as the default value in my variable in my Catalog Item (in a Scoped App)?

 

Note that I tried the following:

 

var gdt = new GlideDateTime().getDisplayValue();gdt.getYear();

 

 

The error went away, but it did not return any value at all.

Note that my variable type is "Single Line Text".