The CreatorCon Call for Content is officially open! Get started here.

Customer would like a choice (i.e., drop down) field that they can select a Year (i.e., YYYY)

Jeff Wentworth
ServiceNow Employee
ServiceNow Employee

A customer has a current requirement where they would like a drop down (i.e., choice) field to present current and past years for a user to make a selection.

  • I have reviewed the Docs, Community, and YouTube, but have not seen a solution surface.
  • Has anyone successfully configured something like this?
  • I'm attaching a generic example of the requirement.

Thanks in advance for any support! 🙂

3 REPLIES 3

Jeff Wentworth
ServiceNow Employee
ServiceNow Employee

Here's the image that I attached previously. -- Thanks again! 🙂

 

Drop_down_field_presents_Years.png

 

For this field, configure the choices dynamically using a script. You can use a Server Script or a Business Rule script to generate the list of years. Here's an example of how you can achieve this using a Server Script:

var yearChoices = [];
var currentYear = new Date().getFullYear();
var earliestYear = currentYear - 10; // You can adjust this range as needed

for (var year = currentYear; year >= earliestYear; year--) {
    yearChoices.push(year.toString());
}

// Set the choices on the field
current.u_review_year.setChoiceList(yearChoices.join(','));

Bert_c1
Kilo Patron

Hello Jeff,

 

It looks like "Review Year" is defined as a choice field in the system dictionary.  And accessing that dictionary record you should see a "Choices" tab on the form. You can add choices there.  Maybe you want to dynamically create the choices based the current year. But that is not clear from your post.