- 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:39 AM
Hi JJG,
This is scoped right if I remember most of your other questions?
If so, the solution of Vaibhav will work fine. Only the gs.print will not work, be aware of that.
Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP
---
LinkedIn
Community article list
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-13-2020 09:41 AM
Hi,
No need of Business rule you can pass the default value for the field to be something as below.
javascript:var gdt = new GlideDateTime().getDate();gdt.getByFormat('MMM - YYYY');
Thanks,
Jaspal Singh