Difference between revisions of "SmartCheck Validation"

From SmartWiki
Jump to: navigation, search
Line 32: Line 32:
 
If the statement is true, set the value of the statement to “false” and print the custom message below.
 
If the statement is true, set the value of the statement to “false” and print the custom message below.
 
<pre>
 
<pre>
    result.addMsg('Some message here');
+
result.addMsg('Some message here');
    }
+
}
 
</pre>
 
</pre>
  

Revision as of 16:32, 4 December 2015

Template:UnderConstruction

Overview

SmartCheck Validation enables your SmartSimple system to perform server-side field validations ensuring that applications and forms are properly completed.
These validations are performed on “submit” action and returns failed field entries with your defined error messages. These messages are displayed at the top of the form and on-click can take the user to referenced field.

SmartCheck Validation Structure

Each SmartCheck Validation statement shares the following structure:


  • If Statement (thing to be compared)
  • Result (true or false result)
  • Message (to be displayed on failed result)


In the example below:

if(ssParseNum(form.getStr("cf_Store Value")) > 5)
    {result.isPassed=false;
    result.addMsg('Some message here');
   }

Recognize the If, Result, Message structure:

if(ssParseNum(form.getStr("cf_Store Value")) > 5)

If the contents the of the form value (stored in the custom field named cf_Store_Value) is greater than 5.

{result.isPassed=false;

If the statement is true, set the value of the statement to “false” and print the custom message below.

result.addMsg('Some message here');
}

Enabling SmartCheck Validation

SmartCheck Validation can be enabled system-wide or on a UTA by UTA basis.

Before you can enable SmartCheck Validation on your system you’ll need to have Global Admin privileges. To enable the feature system-wide:

  1. Under the Configuration menu click on Global Settings.
  2. Add a check mark to the “Activate SmartCheck Validation” box under System Configuration.

To enable the feature on a specific UTA:

  1. Navigate to the desired UTA# Click on “Settings”# Under the L1 or L2, click on the “SmartCheck Validation” link under the Properties menu. # Click on “New Validation”# Using the “Code Builder” or “Source” tabs, enter your validation details.# Click Save when done

Examples

Application Name field black -> Fail:

if(form.getStr("sf_Application Name") == "")
    {result.isPassed=false;
    result.addMsg('Application name cannot be blank');
    }

Requested Amount less than X -> Fail:

if(ssParseNum(form.getStr("cf_Requested Amount")) < "5000")
    {result.isPassed=false;
    result.addMsg('cf_@Requested Amount.id@','Field test message');
    }

Number value greater than 5 -> Fail:

if(ssParseNum(form.getStr("cf_Store Value")) > 5)
    {result.isPassed=false;
    result.addMsg('Some message here');
    }

Single field upload field has no file -> Fail:

if("@Single File Field.filename@" == "")
    {result.isPassed=false;
    result.addMsg('Please upload a file here');
    }

Multi file upload field has no files -> Fail:

if(ssParseNum("@level1.MUlti upload.numoffiles@") < 1)
    {result.isPassed=false;
    result.addMsg('Please upload at least one file');    }

End date is before Start date -> Fail:

if (datediff('@date(startdate)@','@date(enddate)@','d') < 0)
    {result.addMsg('End date must be later than Start date'));
    result.isPassed=false;
    }

To include other scripts from SmartCheck script:

//@include(AnotherSmartCheckScriptName)