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

Requirement

Start date + Months = End date - 1 day

When to run

When: Before
Filter Conditions: Start date changes OR Months changes

 

Thanks.

Hi Chaquino,

I am performing on incident table as you havent mentioned the exact requirement.Change as per your requirement.

 

var gr=new GlideRecord('incident');
gr.addQuery('number','INC0010213');
gr.query();
while(gr.next())
{
var date1=gr.sys_created_on;

var f = new GlideDateTime(date1);
f.addMonths(24);
f.addDays(-1);

gs.addInfoMessage(f);
}

 

mark correct/helpful based on impact.

Thanks,

Dhananjay.

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