Validations on Form Submission

If somebody had checked that they wanted to create a note, then, let’s force them to input something!

We’ll do the same for the task data. They can only submit the form with the task box checked if they have filled out all the task fields.

Validations, and differentiating between isEmpty(), isNull(), isBlank(), or another variation like == “”, can be very difficult. And, curiously enough, even though it worked in the video, the isNull() documentation actually says it’s not applicable to Creator.

The most reliable for text fields is to use the == “” phrase, for dates, the == null (actually typing out the word ‘null’, because that is what is returned when you try and ‘get’ and empty date field), and for picklist/dropdowns, use .isEmpty()

NOTE: In order to test your form, if you’re planning on pre-populating data in via a button or other link, you’ll need to “pre-fill” your hidden ID fields using URL parameters. If you, from the ‘Edit’ view of your form, click on the blue ‘Access Development Live’ button in the top right and then append your URL parameter (e.g. “?Deal_ID=1111122222333334444”) it will work. It WILL NOT work, however, if you, in environments, click ‘Access’ under the Development environment.

shouldWeCancel = "";
if(add_note && input.Note == "")
{
 shouldWeCancel = "YES";
}
if(create_task && (input.Task_Subject == "" || input.Due_Date == null || input.Priority.isEmpty()))
{
 shouldWeCancel = "YES";
}
if(shouldWeCancel == "YES")
{
 alert "Hey, you need to fill out all fields!";
 cancel submit;
}
Back to Lesson