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

It should be a Before business rule, and shouldn't use current.update().  


It should be a before business rule and you only need 1 business rule



On Friday, August 26, 2016, AEBongiovanni <community-no-reply@servicenow.com>


It should be a before business rule and you only need 1 business rule



On Friday, August 26, 2016, AEBongiovanni <community-no-reply@servicenow.com>


Abhinay Erra
Giga Sage

What you can do is, make your choice list values as 1,2,...12. Now in your before business rule use this to set the choice field


var gdt = new GlideDateTime();


current.<creation month field name>=gdt.getMonthLocalTime();


var gdt1 = new GlideDateTime();


gdt1.setValue(current.<implementation date field>);


current.<implementation month>=gdt1.getMonthLocalTime();