Skip to main content
Participant
October 24, 2023
Answered

Add 90 days or 30 days depending on a percentage.

  • October 24, 2023
  • 1 reply
  • 420 views

I'm currently working on a calculation and want to auto-calculate that if the total shows less than 10% it will add 30 days on a due date and if more than 10% it would be 90 days. The accommodation is a percentage and not a whole number. 

This topic has been closed for replies.
Correct answer MightyRed_

I found the answer 

 

var s1 = this.getField("Effective Date").valueAsString;
var s2 = this.getField("RentIncrease").valueAsString;

if (s1 === "" || s2 === "") {
event.value = "";
} else {
var d1 = util.scand("mm/dd/yyyy", s1);

// Assuming RentIncrease is in percentage format like "10%"
var rentIncrease = parseFloat(s2);

if (rentIncrease >= 10) {
// If RentIncrease is 10% or more, add 90 days
d1.setDate(d1.getDate() + 90);
} else {
// If RentIncrease is less than 10%, add 30 days
d1.setDate(d1.getDate() + 30);
}

event.value = util.printd("mm/dd/yyyy", d1);
}

1 reply

MightyRed_AuthorCorrect answer
Participant
October 24, 2023

I found the answer 

 

var s1 = this.getField("Effective Date").valueAsString;
var s2 = this.getField("RentIncrease").valueAsString;

if (s1 === "" || s2 === "") {
event.value = "";
} else {
var d1 = util.scand("mm/dd/yyyy", s1);

// Assuming RentIncrease is in percentage format like "10%"
var rentIncrease = parseFloat(s2);

if (rentIncrease >= 10) {
// If RentIncrease is 10% or more, add 90 days
d1.setDate(d1.getDate() + 90);
} else {
// If RentIncrease is less than 10%, add 30 days
d1.setDate(d1.getDate() + 30);
}

event.value = util.printd("mm/dd/yyyy", d1);
}