Skip to main content
Known Participant
March 8, 2025
Question

Calculating LTARV and LTC

  • March 8, 2025
  • 1 reply
  • 1675 views

I'm trying to utilize scripts to calculate the LTV, LTARV and LTC as percentages in this pdf. It's not returning values for LTARV and LTC. The LTV calculation is only returning an error if the TransactionType field contains "Purchase" and the PurchasePrice field is left blank (which is correct). I've attached the form for reference.

 

Here's the formula that chat gpt advised for the LTARV:

 

// Get the values from the fields

var loanAmount = this.getField("LoanAmount").value;

var asRepairedValue = this.getField("AsRepairedValue").value;

var loanType = this.getField("LoanType").value;

 

// Initialize the LTARV result

var ltarvResult = "";

 

// Check the LoanType and calculate LTARV or set the value to "N/A"

if (loanType === "Bridge w/ Rehab" || loanType === "Ground Up Construction") {

    if (asRepairedValue != 0) {

        ltarvResult = loanAmount / asRepairedValue;

    } else {

        ltarvResult = "N/A";

    }

} else if (loanType === "Stabilized Bridge" || loanType === "DSCR") {

    ltarvResult = "N/A";

}

 

// Set the value of LTARV field

event.value = ltarvResult;

 

The formula that was advised for the LTC is:

 

var loanAmount = this.getField("LoanAmount").value; var costBasis = this.getField("costBasis").value; var LTC; if (!isNaN(loanAmount) && !isNaN(costBasis)) { LTC = laonAmount / costBasis; } else { event.value = "Error"; } if (costBasis !== 0) { // Avoid division by zero event.value = loanAmount / costBasis; } else { event.value = "Infinity or Error"; }

1 reply

try67
Community Expert
Community Expert
March 8, 2025

Check the JS Console. There are errors in your code.

Known Participant
March 8, 2025

Thanks for the reply, the error part goes without saying. I'm trying to determine what are the errors.

try67
Community Expert
Community Expert
March 8, 2025

These are the error messages:

 

TypeError: this.getField(...) is null
4:Field:Calculate
TypeError: this.getField(...) is null
2:Field:Calculate

 

They mean you entered two incorrect field names in your calc scripts.