Business rule to set field with Month/Year from date field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-19-2016 09:07 AM
I want to use a business rule to get the Month and Date from a Date field, and then populate a string field with those values. Both fields are on the same table (time_card).
Thanks for the help!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2017 08:11 AM
(function executeRule(current, previous /*null when async*/) {
var date = g_form.getValue('u_datetimeoccurance');
var m = date.getDate().getByFormat('M');
var y = date.getDate().getByFormat('yyyy');
g_form.setValue('u_monthyear',m+' '+y);
})(curent, previous);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2017 08:13 AM
so the type of 'u_datetimeoccurance' is Date/Time right?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2017 08:18 AM
Correct and u_monthyear is a string

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2017 08:27 AM
kim.sullivan@postproperties.com
here is your code
var gdt= new GlideDateTime(current.u_datetimeoccurance.getDisplayValue());
current.u_monthyear=gdt.getMonthLocalTime()+' '+getYearLocalTime();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2017 08:12 AM
Here's what is working for me:
updateMonthYear();
function updateMonthYear() {
// Update the Month and Year based on Time Starts On field
var gDT = new GlideDateTime(current.week_starts_on);
var year = gDT.getYearUTC();
var month = gDT.getMonthUTC();
var monthNames = ["01", "02", "03", "04", "05", "06",
"07", "08", "09", "10", "11", "12"];
var monthName = monthNames[month - 1];
current.u_month_year = year + " - " + monthName;
}