Urgent :: Populate month based on date in a field

arnabbose
Tera Expert

Hello Experts,

I have a really Urgent requirement. I have two drop down fields on my Custom Table, Creation Month and Implementation Month - Both have values from January to December.

I have couple of requirements:

1. The Creation Month will be populated based on month when I submit a record for that table. Say I submit today ; Creation Month = August

2. There is a field called implementation date on my Form. Once I select the date, the Implementation Month will auto-populate in accordance. So, basically

      if say implementation date is : 2016 - 10 - 10

      then Implementation Month = October  

Can anyone tell me how to do it OR better provide a sample code for this?

1 ACCEPTED SOLUTION

adi91221
Kilo Guru

Hi Arnab



First check the values of Creation Month and Implementation Month choice values and give the values 1 to 12 respectively from jan to dec


then write onAfter business rule.




var cMonth = new GlideDateTime(current.creationdate);


current.creationMonth = cMonth.getMonth();


var iMonth = new GlideDateTime(current.creationdate);


current.ImpMonth = iMonth.getMonth();


current.update();



Thanjs


Adi


View solution in original post

8 REPLIES 8

Duodecimal
Mega Guru

OK - so your custom table should be using a choice list for Creation Month and Implementation Month.   You would set the Labels of these choices to be the English-language month names as you have now, but set the Values to be the numbers 1-12.



That way you can use GlideDateTime.getMonthLocalTime() to get a number.   Since Creation Month will default to when the record is submitted, you can have the default value be "javascript:var gdt = new GlideDateTime();gdt.getMonthLocalTime();"



You can do the same thing in a business rule as well, and should do so for Implementation Month.   It would be a Before business rule when the field "Implementation Date" changes.   The business rule script would be something like "current.u_implementation_month = (new GlideDateTime(current.u_implementation_date)).getMonthLocalTime();"


Thank you.

adi91221
Kilo Guru

Hi Arnab



First check the values of Creation Month and Implementation Month choice values and give the values 1 to 12 respectively from jan to dec


then write onAfter business rule.




var cMonth = new GlideDateTime(current.creationdate);


current.creationMonth = cMonth.getMonth();


var iMonth = new GlideDateTime(current.creationdate);


current.ImpMonth = iMonth.getMonth();


current.update();



Thanjs


Adi


Thanks everyone, did both by BRs...
Working great, but the system performance seems to have taken a beating...