Check Lock Status and Stamp Closure Date
This button checks whether a loan is currently locked before stamping today's
date into a custom field. If the loan is locked, it alerts the user to transfer
or cancel the lock before proceeding. If the loan is not locked, it records
today's date in the custom field CX.CLOSED.FOR.INCOMPLETENESS and
recalculates the loan.
The code
async function Button2_click(ctrl) {
// Retrieve the loan object
const loan = await elli.script.getObject("loan");
// Check if the loan is locked (Field 2400)
const lockField = await loan.getField("2400");
const isLocked = lockField === true || lockField === "true" || lockField === "Y";
if (isLocked) {
// Notify user that the loan is locked and action is required
alert(
"Loan is Locked: The lock needs to be transferred to a new loan " +
"or have the lock cancelled with the Lock Desk and then disposition the file."
);
} else {
// Get today's date formatted as YYYY-MM-DD
const today = new Date();
const formattedDate = [
today.getFullYear(),
String(today.getMonth() + 1).padStart(2, "0"),
String(today.getDate()).padStart(2, "0")
].join("-");
// Stamp the date into the custom field and recalculate the loan
await loan.setFields({ "CX.CLOSED.FOR.INCOMPLETENESS": formattedDate });
await loan.Calculate();
}
}
How to use it
- In Encompass, open your web form in the form builder
- Add a button to your form and name it
Button2 - Paste this code into the button's click event handler
- Update
CX.CLOSED.FOR.INCOMPLETENESSto match your actual custom field ID if different - Save and test by opening a locked loan and an unlocked loan to verify both paths work
Notes
Notes
- Field
2400is the standard Encompass rate lock field — this should work without changes - The date is stamped in
YYYY-MM-DDformat — change thejoin("-")separator if your field expects a different format likeMM/DD/YYYY CX.CLOSED.FOR.INCOMPLETENESSis an example custom field — replace this with your own custom field ID from your Encompass environment. Custom fields always start withCX.- The
await loan.Calculate()at the end ensures any dependent fields update immediately