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

Voona Rohila
Mega Patron
Mega Patron

Hi Pushpa

 

I think for this you will have to create custom fields with drop down values for year 2019,2020, 2021.

 


Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP

Gaurav Shirsat
Mega Sage

Hello

Then this is not possible; Date field always store date in YYYY-mm-DD format.

You can not make change in servicenow OOB variables.

Please Mark Correct and Helpful
Thanks and Regards
Gaurav Shirsat

Sohail Khilji
Kilo Patron

 

Well there are multiple ways to achieve this it depends on the requirement and what form you are working on, below are the items that can help you:

If you're working on catalogue item you can create your macro that shows only the year field as years YYYY

If you are working on a form level below options help you:
1. Create a string field make it to accept only integer (isNaN) and limit the field to four digits.
2. Create a choice list and use background script to populate the choices for one time.
3. If your working on date field then you have to to use regex to validate the date field to trim the month & date i.e. DD/MM/


Please let me know where exactly your requirement is so I shall help you further. Kindly mark the answer helpful if helped.


☑️ Please mark responses as HELPFUL or ACCEPT SOLUTION to assist future users in finding the right solution....

LinkedIn - Lets Connect

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