- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-13-2020 09:21 AM
Hello,
I have a string field called 'month'. I would like to default value to be set to the current month and year.
For example: If I inserted a record today, the 'month' field should be April - 2020
I figure that ill need to create a before insert business rule to achieve this but I do not know how to get only the year and month. Any help is appreciated.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-13-2020 09:31 AM
Hi
Try this
// Execute this at "SCRIPTS- BACKGROUND" for test purposes.
var gDate = new GlideDateTime().getDate();
gs.print(gDate.getByFormat('MMMMM - YYYY'));
For default Value use this :
// This script line is useful for default value
javascript: new GlideDateTime().getDate().getByFormat('MMMMM - YYYY');
Mark it correct and helpful if it helps you
Regards,
Vaibhav Chaudhari

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-13-2020 09:31 AM
Hi
Try this
// Execute this at "SCRIPTS- BACKGROUND" for test purposes.
var gDate = new GlideDateTime().getDate();
gs.print(gDate.getByFormat('MMMMM - YYYY'));
For default Value use this :
// This script line is useful for default value
javascript: new GlideDateTime().getDate().getByFormat('MMMMM - YYYY');
Mark it correct and helpful if it helps you
Regards,
Vaibhav Chaudhari
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-13-2020 09:48 AM
Wont that get me the month as a number? I need it as a string
ex: not 04, but instead as 'April'

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-13-2020 09:55 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-13-2020 10:06 AM
Hi,
use this in the before insert BR
var year = new GlideDateTime().getYear();
var gd = new GlideDate();
var monthName = gd.getByFormat("MMMM");
current.<string_field> = monthName + ' - ' + year;
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader