how to create a business rule for add days in a field date
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2022 06:11 AM
Hey guys. I need to automatically calculate the contract end date.
I need to make a business rule where it takes the "Start date" field:
Add the days in the "Term of contract" field:
Where 1 year adds up to 365 days and 2 years adds up to 730 days.
And put the result in date format in the "End date" field:
Fields:
- Start date | starts
- End date | ends
- Contract term | u_contract_term
Table:
- Contract | ast_contract
I don't even know where to start in scripting, I'm terrible at scripting.
I don't have anything yet.
Thank you so much ❤️
1 REPLY 1
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2022 06:21 AM
Hi @Lucas11 ,
You can try below code :- in BR
(function executeRule(current, previous /*null when async*/ ) {
var StartDate = new GlideDateTime(current.starts);
if (current.contract_term == '1_year') { //write down proper field name and backend value for 1 year
StartDate.addDaysUTC(365);
} else if (current.contract_term == '2_year') { //write down proper field name and backend value for 2 year
StartDate.addDaysUTC(730);
}
current.ends = StartDate;
current.update();
})(current, previous);