How to select the only year in date field

Pushpa
Mega Expert

Hi Team,

 

How to select only year from date field.

please any one help on this.

 

Regards,

Pushpa

1 ACCEPTED SOLUTION

Hi,

for that you can use onLoad client script with GlideAjax

1) script include will check which is the current quarter and based on that hide the other quarter

Sample script to determine the quarter in server side

var test = new GlideDateTime();

var month = test.getMonth();

var quarter = Math.ceil(month/3);

gs.info('Current quarter is->'+quarter);

Output:

[0:00:00.069] Script completed in scope global: script


Script execution history and recovery available here


*** Script: Current quarter is->2

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

12 REPLIES 12

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

Please explain your business requirement in detail.

Since that is OOB Date field you need to select the complete date year, month and day

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Hi Ankur,

i have Quarter drop down field Q1,Q2,Q3,Q4 i want to select year one more field. (only year need to select)

 

Regards,

Pushpa

Hi,

then you need to create choice values and use choice field

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Hi,

If we Choose 2021..
 
since current Month is June.. only Q2 Q3 Q4 should be visible.
if current year is 2021 and current month is september, then Q3& Q4 shouble be visible.
 
If we choose 2022 .......and later, all quaters should be visible..
 
conditions should help for the current year and current month.
 
please help me with the script where to define and please guide me .
 
Regards
Pushpa k

 

 

Hi,

for that you can use onLoad client script with GlideAjax

1) script include will check which is the current quarter and based on that hide the other quarter

Sample script to determine the quarter in server side

var test = new GlideDateTime();

var month = test.getMonth();

var quarter = Math.ceil(month/3);

gs.info('Current quarter is->'+quarter);

Output:

[0:00:00.069] Script completed in scope global: script


Script execution history and recovery available here


*** Script: Current quarter is->2

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader