Need Business Rule: Start date + Months = End date - 1 day

Desmo
Mega Guru

Hello,

Need a Business Rule to run the following scenario:

Start date + Months = End date - 1 day

  • Start date (Date field), i.e. 12/20/2019
  • Months (String field), i.e. 24
  • End date (Date field), 12/19/2021

Months may need to be a different field type in order for the script to work. It can be changed.

 

Thank you.

1 ACCEPTED SOLUTION

Desmo
Mega Guru

Used the information others provided to create a Business Rule.

 

//Start date
var sdate = current.your_start_date_field_name;

//Months. Must be an integer field type.
var mon = current.getValue('your_term_field_name');

//End date
var edate = new GlideDateTime(sdate);

//Add months and substract day(s)
edate.addMonths(mon);
edate.addDays(-1);	

current.your_end_date_field_name = edate;

})(current, previous);


View solution in original post

7 REPLIES 7

Harsh Vardhan
Giga Patron

can you add more details about this requirement ?

 

you can try with below sample code:

 

var mon = 24;
var sd = new GlideDateTime();
sd.addMonths(mon);
gs.print(sd.getDate());

var edt = new GlideDateTime();
edt.addDays(-1);
gs.print(edt.getDate());


if(sd.getDate() == edt.getDate()){
gs.print('hey if');
}
else{
gs.print('else');
}

Months is not a set value.

 

Thanks.

how will you get month ? any field there , which will hold month value ? if yes use below line. 

 

var mon = current.getValue('month field');

Dhananjay Pawar
Kilo Sage

Hi,

What is your exact requirement?At what condition you want to add months?

Thanks,

Dhananjay.