Business rule to set field with Month/Year from date field

swnewton
Kilo Guru

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!

25 REPLIES 25

(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);


so the type of 'u_datetimeoccurance' is Date/Time right?


Correct and u_monthyear is a string


kim.sullivan@postproperties.com


here is your code




var gdt= new GlideDateTime(current.u_datetimeoccurance.getDisplayValue());


current.u_monthyear=gdt.getMonthLocalTime()+' '+getYearLocalTime();


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;


}