Business rule to calculate a Date from another Date minus XX days
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-27-2018 03:04 AM
Hi,
I am trying to create a business rule which will take one Date value from a field, then based on selection of choice another field return a new date in other field, its to work out a review date on a contract based on end date, initially one choiuce only, but there would be two choices
ends - the date the contract due to end
u_ck_renewal_or_termination_period - the selection used to determine the new date
renewal_end_date - where I want the date calculated entered
I have tried the following script, which doesn't seem to work, using Istanbul, no conditions, before, on uodate, insert, any suggetsions on my error, ommsision or alternative methods would be apprecaited
Many thanks
Table: ast_contract
(function executeRule(current, previous /*null when async*/) {
var gdt = current.ends.getGlideObject();
if (current.u_ck_renewal_or_termination_period =='3 Months'){
current.renewal_end_date=gdt.subtractDays(90);
}
})(current, previous);
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2018 01:55 AM
HI All, thanks for your response, still not working, the add(-90) that Ram and Mike work, fired (as info message triggered) but did not result in the field being populated, Archanareddy's fired but just set same value of GDT without the desired subtraction.
I set up a test date field to see if there was any legacy rules in place on the OOB renewal_end_date, but that test date field behaved exactly the same using both the scripts suggested

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2018 03:46 AM
Hi Chris Waters,
Try this edited code and let me know if this helped you.
var gdt = current.ends.getGlideObject();
if (current.u_ck_renewal_or_termination_period =='3 Months'){
gdt.addDays(-90);
current.renewal_end_date=gdt;
Mark the answer as Correct/Helpful based on its impact.
Thanks,
Archana
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2018 03:38 AM
Thanks for all your replies, I am using a different desitination field now renewal_date
Using either AddDays(-90) or AddDaysLocalTime(-90) will set the date field correctly, however what it seems to do now to also change the originating date to the same value, so ends the Contract End date to be that of the new calculated time value
function executeRule(current, previous /*null when async*/) {
gs.addInfoMessage("You updated the expiry date");
var gdt = current.ends.getGlideObject();
if (current.u_ck_renewal_or_termination_period =='3 months'){
gdt.addDaysLocalTime(-90); -Here addDays works as well
current.renewal_date=gdt; -Here current.setValue('renewal_date', gdt.getValue()); also seems to work
}
})(current, previous);
The issue is now that the contract end jumps to be the same value as the new date created, when I want that to remain as it was
For example - set a contract to run for a year
Fire the rule that subtracts the dates from the GDT and populates the new field 90 days before the end
But this then affects the Contract end date to the same date, when it should be left alone, i.e still the 01/06/2019
Any idea what I am doing wrong?
Thanks
Chris
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2018 03:50 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2018 03:58 AM
Hi Chris,
With the script provided in this thread, there is no chance of this happening. May I know if you have added any other script to it.
Also, please check the Calculated Value and dependent fields of Ends field in the dictionary.
Thanks