How to default a text box to display current year
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-30-2016 09:27 AM
How to default a text box to display current year.
Thanks,
Anji
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-30-2016 09:40 AM
Add this line in UI page in client script section.
txtYear.value = new Date().getFullYear();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-30-2016 09:46 AM
You want me to enter that code in default section of the field?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-30-2016 09:51 AM
No, For table columns, you can't specify an expression, unless its calculated. As this field is not calculated column, we should do it on form.
Create a client script for this table -> Implement "Onload" event, in the script, write like below.
g_form.setValue('your field name here ',new Date().getFullYear());
Following link will help you to understand more about client scripts.
Client Scripts - ServiceNow Wiki
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-30-2016 10:04 AM
Actually, you can set the Default to the following code:
javascript:(new Date().getFullYear()).toString().substr(0,4);
I had to add the extra "substr" method because without it, the year ended up with an extra ".0" at the end of it for some reason.