- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2019 08:06 AM
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 .
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2019 08:21 AM
Hi,
Try using javascript: var gdt = new GlideDateTime(gs.nowDateTime());gdt.getYear();
Thanks,
Jaspal Singh
Hit Helpful or Correct on the impact of response.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2019 08:10 AM
Try: gs.now().getByFormat(‘yyyy’);
Please mark as correct/helpful if this answered your question!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2019 08:19 AM
Not working , gs.now().getByFormat(‘yyyy’); returning empty value .

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2019 08:21 AM
Hi,
Try using javascript: var gdt = new GlideDateTime(gs.nowDateTime());gdt.getYear();
Thanks,
Jaspal Singh
Hit Helpful or Correct on the impact of response.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-21-2024 07:08 AM - edited 03-21-2024 07:34 AM
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".