APPROVED ANSWER
SELECTED ANSWER
replied on November 19, 2024
The new designer is unique from classic in that it actually runs the JavaScript on every process step including save to repository. In a save to repository step forms are marked readonly so attempting to set them via JS will throw an error. You should (always) handle errors gracefully in cases you are modifying form state. I am actively updating our documentation to provide better examples of this. You can also use the LFForm properties to determine the status of the form
try {
LFForm.setFieldValues({fieldId: 16}, {address1: "1234 New Road", address2: "Suite 150", zipcode: "99999", city: "City", province: "ST", country: "USA"});
} catch (err) {
console.warn(err)
}
// OR
LFForm.setFieldValues({fieldId: 16}, {address1: "1234 New Road", address2: "Suite 150", zipcode: "99999", city: "City", province: "ST", country: "USA"})
.catch(err => console.warn);
// Best way
if (LFForm.isReadonly === false && LFForm.isDisabled === false) {
try {
LFForm.setFieldValues({fieldId: 16}, {address1: "1234 New Road", address2: "Suite 150", zipcode: "99999", city: "City", province: "ST", country: "USA"});
// form logic
} catch (err) {
console.warn(err)
}
}