SmartCheck Validation statements follow a consistent statement structure, currency parsing functions, message syntax, and example code in SmartSimple.
Validation Statement Structure
Each SmartCheck Validation statement follows the same three-part structure:
- If statement - The condition to evaluate.
- Result - The outcome assigned based on the condition.
- Message - The text displayed when the result is false.
In the annotated example below, the statement checks whether the form value cf_Store_Value is greater than 5.
if(ssParseNum(form.getStr("cf_Store Value")) > 5)The If line checks the condition.
result.isPassed=false;
Setting the Result to false marks the validation as failed and displays the message below.
result.addMsg("Some message here");The Message line defines the text shown when validation fails.
Currency Parsing Functions
When a custom field stores currency and the format varies by locale, use ssParseNumFromCurrency to convert the value to a number before comparing it:
ssParseNumFromCurrency(value, locale, getnumtype, emptyok)
-
@sslocale@returns the locale of the logged-in user, for example "fr-CA". - getnumtype: 1 returns a real number (10000,78 becomes 10000.78); 2 returns formatted currency (10000,78).
- emptyok: the field may be empty.
Example: ssParseNumFromCurrency("10000,78","fr-CA",1,true) returns 10000.78.
if(ssParseNumFromCurrency(form.getStr("cf_myCADcurrency"),"@sslocale@",1,true) > 5) {
result.isPassed=false;
result.addMsg("Some message here");
}For currencies whose format stays constant regardless of the user's locale, such as DKK, supply the locale directly or use getLocalestrByCurrency to return the default locale for a currency code:
ssParseNumFromCurrency(value,getLocalestrByCurrency('DKK'),1,true)
ssParseNumFromCurrency(value,"da-DK",1,true)
if(ssParseNumFromCurrency(form.getStr("cf_myDKKcurrency"),"da-DK",1,true) > 5) {
result.isPassed=false;
result.addMsg("Some message here");
}Message Syntax
SmartCheck supports system messages, field-specific messages, and language-specific messages.
System message - Displays at the top of the form.
result.addMsg("Your message goes here.");Field message - Displays at the top of the form and on the named custom field.
result.addMsg("cf_@field name.id@", "Your message goes here.");Note-enabled field message - Include h before the field reference.
result.addMsg("cf_h@notefield.id@","You must type in a description before submitting for revisions.");Language-specific message - Add the langid after the message text.
result.addMsg("Your message goes here.", 1);
result.addMsg("cf_@field name.id@", "Your message goes here.", 1);Example with multiple languages:
if(((form.getStr("cf_Strategy").length() -
form.getStr("cf_Strategy").replace(';','').length())>4)) {
result.isPassed=false;
result.addMsg("cf_@Strategy.id@","You can pick up to 4 primary strategies you use.", 1);
result.addMsg("cf_@Strategy.id@","Puedes elegir 4 estrategias principales.", 14);
result.addMsg("cf_@Strategy.id@","Vous pouvez choisir à 4 stratégies primaires", 6);
result.addMsg("cf_@Strategy.id@","Você pode escolher 4 estratégias primárias.", 16);
}Validation Examples
Use the following examples as starting points. Replace the field names and messages with values from your own configuration.
Amount and Number Checks
Check that an amount does not exceed $100,000.00:
if(ssParseNum(form.getStr("cf_Amount Requested")) > 100000) {
result.isPassed=false;
result.addMsg("cf_@Amount Requested.id@","Amount Requested cannot exceed $100,000");
}Check that a requested amount is at least a set value:
if(ssParseNum(form.getStr("cf_Requested Amount")) < 5000) {
result.isPassed=false;
result.addMsg("cf_@Requested Amount.id@","Field test message");
}Check that a number value does not exceed 5:
if(ssParseNum(form.getStr("cf_Store Value")) > 5) {
result.isPassed=false;
result.addMsg("Some message here");
}Required Field Checks
Require a standard text field, such as Application Name:
if(form.getStr("sf_Application Name") == ""){
result.isPassed=false;
result.addMsg("Application name cannot be blank");
}Require a date custom field:
if ((ssConvertDate(form.getStr("cf_Project Start Date"), "@dateformat@", "yyyy-mm-dd") == "")) {
result.isPassed = false;
result.addMsg("cf_@Project Start Date.id@", "Project Start Date is a required field.");
}Require a single file upload field to contain a file:
if("@Single File Field.filename@" == "") {
result.isPassed=false;
result.addMsg("Please upload a file here");
}Require at least one file in a multi-file upload field:
if(ssParseNum("@level1.MUlti upload.numoffiles@") < 1) {
result.isPassed=false;
result.addMsg("Please upload at least one file");
}Require at least one entry in a dynamic XML field:
if("@xml.fieldname.sectionnodename.rownodename.nodecount@"==0) {
result.isPassed=false;
result.addMsg("xml_@fieldname.id@","At least one entry is required in the XML worksheet.");
}Require at least one role to be selected on a contact:
if("@rolelist@" == "") {
result.isPassed=false;
result.addMsg("At least one role must be selected.");
}Require at least one contact in a specific role:
if("@level1.[#(?object=contact::criteria=rolename IN ('Panel Reviewer - Pending','Panel Reviewer - Accepted')::groupfunction=count)~userid~#]@" < "1") {
result.isPassed=false;
result.addMsg("Please assign reviewers in the Panel Reviewer Pending or Panel Reviewer Accepted role.");
}Date Comparisons
Compare two date fields that have separate time fields storing 24-hour time:
if(ssConvertDate(form.getStr("cf_Event Start Date"),"@dateformat@", "yyyy-mm-dd")+' '+form.getStr("cf_Event Start Time") >= ssConvertDate(form.getStr("cf_Event End Date"),"@dateformat@", "yyyy-mm-dd")+' '+form.getStr("cf_Event End Time")) {
result.isPassed=false;
result.addMsg("cf_@Event End Time.id@","End Date must take place after the Start Date");
}Compare a date field to the current date:
if ((ssConvertDate(form.getStr("cf_Individual Review Start Date"), "@dateformat@", "yyyy-mm-dd") > "@date(currentdate)@")) {
result.isPassed = false;
result.addMsg("cf_@Individual Review Start Date.id@", "Please enter a date less than or equal to today for the date.");
}Require a date at least six months in the past:
if(ssConvertDate(form.getStr("cf_Date"),"@dateformat@", "yyyy-mm-dd") > "<!--@sscalculation(DATE_ADD('@date(currentdate)@', INTERVAL -6 MONTH))-->"){
result.isPassed=false;
result.addMsg("cf_@Date.id@","Date must be at least 6 months prior to today's date");
}Compare two date fields that also store time:
if(ConvertDateTimeStr(form.getStr("cf_Cycle Start Date"),"@dateformat@", "yyyy-mm-dd") >= ConvertDateTimeStr(form.getStr("cf_Cycle Deadline"),"@dateformat@", "yyyy-mm-dd")) {
result.isPassed=false;
result.addMsg('cf_@Cycle Deadline.id@','The submission deadline date cannot be before the open date');
}Require a date at least three business days away:
if(ssConvertDate(form.getStr("cf_Date EOI Revision Deadline"),"@dateformat@",'yyyy-mm-dd') < "<!--@sscalculation(SS_FUNC.addbusdays('@date(currentdate)@',3))-->") {
result.isPassed=false;
result.addMsg("cf_@Date EOI Revision Deadline.id@","Date must be at least 3 business days away");
}Selection Checks
Check whether a Select Many checkbox field includes a specific value:
if(form.getStr("cf_Request Type").indexOf("General Operating")==-1 ) {
result.isPassed=false;
result.addMsg("General Operating was not selected");
}To trigger when the value is selected, use != -1. This approach is typically combined with another field.
Require at least five values in a Select Many checkbox field:
if(((form.getStr("cf_Check Box Field").length() - form.getStr("cf_Check Box Field").replace(';','').length())<=4)) {
result.isPassed=false;
result.addMsg("cf_@Check Box Field.id@","At least 5 items must be selected.");
}Format Checks
Validate an email field:
if(!isEmail(form.getStr("cf_Additional Email 1"))) {
result.isPassed=false;
result.addMsg("cf_@Additional Email 1.id@","Please enter a valid email address.");
}Validate an Irish Eircode:
if(form.getStr("whatever") == "something") {
function isValidEircode(eircode) {
const regex = /^(?:[A-Za-z]\d{2}|D6W)\s?[A-Za-z0-9]{4}$/i;
return regex.test(eircode.trim());
}
if(isValidEircode(form.getStr("cf_txt_TrainingLocationEircode")) === false) {
result.isPassed=false;
result.addMsg("cf_1948531","Please add a valid Eircode");
}
}Validate Irish IBAN and BIC bank identifiers:
if(form.getStr("whatever") == "something") {
function isValidIBAN(input) {
const regex = /^IE.{20}$/i;
return regex.test(input);
}
if(isValidIBAN(form.getStr("cf_txt_IBAN")) === false) {
result.isPassed=false;
result.addMsg("cf_1948551","Please add a valid Irish IBAN");
}
function isValidBIC(input) {
const regex = /^(?:.{4})IE.{2,5}$/i;
return regex.test(input);
}
if(isValidBIC(form.getStr("cf_txt_BIC")) === false) {
result.isPassed=false;
result.addMsg("cf_1948552","Please add a valid BIC");
}
}Text Checks
Validate a Note-enabled multiple-line custom field. Include h before the field reference in the message:
if(form.getStr("cf_notefield")=="") {
result.isPassed= false;
result.addMsg("cf_h@notefield.id@","You must type in a description before submitting for revisions.");
}Enforce a minimum word count on a multiline text field:
if(form.getStr("cf_Leadership").split(' ').length < 100) {
result.isPassed=false;
result.addMsg("cf_@Leadership.id@","Leadership question must have a minimum of 100 words");
}Advanced Validations
Validate that an organization status is Active:
if("@client.status@" != "Active") {
result.isPassed=false;
result.addMsg("Please update your Organization Profile then return to this record and click Submit Application.");
}Define values with var before evaluating them:
var countWatch="[#(?object=activity::criteria=typename='Watchlist Scan' and statusname='Scan Run')~count(eventid)~#]";
if(countWatch=="0") {
result.isPassed=false;
result.addMsg("Please run a watchlist scan.");
}Check a limit by reading a custom field into report criteria:
var maxstores="@ReportProperty2(32735,exportdata,,'@displ_FY@::@typeid@')@";
var selectedstore=form.getStr("cf_txt_StoreNumber");
var y=maxstores.indexOf(selectedstore);
if(y!=-1) {
result.isPassed=false;
result.addMsg("cf_@txt_StoreNumber.id@","Test");
}Include another script in a SmartCheck script:
//@include(AnotherSmartCheckScriptName)@
Prevent a specific role (RoleID 18442) from submitting or changing the record status:
IF("[#(?object=contact::criteria=roleid=18442)~userid~,#]".indexOf("@me.userid@,")>=0){
result.isPassed = false;
result.addMsg('cf_@lrlInvitationsCollaborator.id@', 'You are assigned as Collaborator and not allowed to Submit. Please contact the Grant Owner');
}