Difference between revisions of "SmartCheck Validation"

From SmartWiki
Jump to: navigation, search
m (Additional example added.)
 
(46 intermediate revisions by 13 users not shown)
Line 1: Line 1:
 
=Overview=
 
=Overview=
 
 
SmartCheck Validation is a secure server side validation method. It enables custom field validation ensuring that applications and form inputs meets specified criteria and returns. It provides a better user experience than other validation methodologies and is preferred over Submit Logic. With SmartCheck, the user can see error messages in context and in one central place.
 
SmartCheck Validation is a secure server side validation method. It enables custom field validation ensuring that applications and form inputs meets specified criteria and returns. It provides a better user experience than other validation methodologies and is preferred over Submit Logic. With SmartCheck, the user can see error messages in context and in one central place.
  
Before SmartCheck Validation, some error message would pop up individually, one after another, and some messages would appear in one box at the top, depending on how you setup your validation.
+
Before SmartCheck Validation, some error message would pop up individually, one after another, and some messages would appear in one box at the top, depending on how you setup your validation.
  
 
[[image:Smartcheck validationOLD.png]]
 
[[image:Smartcheck validationOLD.png]]
Line 13: Line 12:
 
[[image:Smartcheck validation1.png]]
 
[[image:Smartcheck validation1.png]]
  
Clicking on an in context message, such as the description field above, enables you to temporarily hide the message. Clicking the error message at the top will bring the cursor to the field where the error is present (if there is a corresponding input).  
+
Clicking on the '''x''' within the in context error message, such as the description field above, enables you to temporarily hide the message. Clicking the error message at the top will bring the cursor to the field where the error is present (if there is a corresponding input). The context error message will also disappear when you have modified the value within field in question.
  
  
Before you can use SmartCheck validation you must . . .  
+
Before you can use SmartCheck validation you must . . .
  
 
1. Configure SmartCheck Validation
 
1. Configure SmartCheck Validation
Line 27: Line 26:
  
  
=Configure SmartCheck Validation=
 
  
SmartCheck Validation can be configured for each object type in the system (i.e. individual [[Entity|UTA Level 1/2/3]], company, user, transaction) and then be attached to a Submit button.  
+
=Configure SmartCheck Validation=
 +
SmartCheck Validation can be configured for each object type in the system (i.e. individual [[Entity|UTA Level 1/2/3]], company, user, transaction) and then be attached to a Submit button.
  
  
 
1. Each entity will have a SmartCheck Validation link available in the corresponding Settings page. Click on this to begin the process of configuring the SmartCheck validation statements.
 
1. Each entity will have a SmartCheck Validation link available in the corresponding Settings page. Click on this to begin the process of configuring the SmartCheck validation statements.
+
 
 
[[Image:SmartCheck1.png|700px]]
 
[[Image:SmartCheck1.png|700px]]
  
  
2. The Smartcheck Validation list view will display. There will be a '''New Validation''' button along the top. Click this.  
+
2. The Smartcheck Validation list view will display. There will be a '''New Validation''' button along the top. Click this.
 
[[Image:SmartCheckLV.png|800px]]
 
[[Image:SmartCheckLV.png|800px]]
  
3. The SmartCheck validation screen will display, comprised of the following 3 tabs . . .  
+
3. The SmartCheck validation screen will display, comprised of the following 3 tabs . . .
* Main  
+
 
 +
* Main
 
* Code Builder
 
* Code Builder
* Source  
+
* Source
  
  
4. Enter appropriate name and description text into the relevant fields on the Main tab and click Save.  
+
4. Enter appropriate name and description text into the relevant fields on the Main tab and click Save.
  
 
[[Image:SmartCheck2.png|800px]]
 
[[Image:SmartCheck2.png|800px]]
Line 52: Line 52:
  
 
5. Navigate to the Code Builder tab to add validation using 2 possible approaches.
 
5. Navigate to the Code Builder tab to add validation using 2 possible approaches.
 
+
 
* ''New validation:'' Use the drop-downs at the top of the screen to create new validation. Further details on the options available are provided in the SmartCheck Validation Structure section below.  
+
* ''New validation:'' Use the drop-downs at the top of the screen to create new validation. Further details on the options available are provided in the SmartCheck Validation Structure section below.
  
 
[[Image:SmartCheck3.png|800px]]
 
[[Image:SmartCheck3.png|800px]]
  
  
* ''Existing Submit Logic'': Use the drop-down at the bottom of the screen to select a submit button and any existing validation associated with this button.  
+
 
 +
* ''Existing Submit Logic'': Use the drop-down at the bottom of the screen to select a submit button and any existing validation associated with this button.
  
 
[[Image:SmartCheck4.png|800px]]
 
[[Image:SmartCheck4.png|800px]]
  
  
6. Click on the Insert button under the relevant section. This will take you to the Source tab, and show the updated validation statement.
+
6. Click on the Insert button under the relevant section. This will take you to the Source tab, and show the updated validation statement.
+
 
 
[[Image:SmartCheck5.png|800px]]
 
[[Image:SmartCheck5.png|800px]]
  
Line 71: Line 72:
  
 
8. Use the Trial Run at the bottom of the Source tab to check whether there are errors when the validation statements run.
 
8. Use the Trial Run at the bottom of the Source tab to check whether there are errors when the validation statements run.
 +
  
  
 
=Add SmartCheck Validation to Submit Button=
 
=Add SmartCheck Validation to Submit Button=
 
 
Once the validation statements are created you can start to add the logic to [[Submit & Save Buttons|Submit or Save buttons]].
 
Once the validation statements are created you can start to add the logic to [[Submit & Save Buttons|Submit or Save buttons]].
  
Line 82: Line 83:
  
  
2. The Submit & Save Buttons page is displayed, showing a list of configured buttons. Click on the Edit button for the one you wish to edit.  
+
2. The Submit & Save Buttons page is displayed, showing a list of configured buttons. Click on the Edit button for the one you wish to edit.
  
  
3. Select the SmartCheck Validation option from the corresponding drop-down  
+
3. Select the SmartCheck Validation option from the corresponding drop-down
  
 
[[Image:SmartCheck6.png|800px]]
 
[[Image:SmartCheck6.png|800px]]
  
  
4. Click Save at the bottom of the page.
+
4. Click Save at the bottom of the page.
 
  
  
=Enable SmartCheck Validation= 
 
  
 +
=Enable SmartCheck Validation=
 
# In the top header, click the '''Configuration''' drop down.
 
# In the top header, click the '''Configuration''' drop down.
 
# Select '''Global Settings'''.
 
# Select '''Global Settings'''.
Line 102: Line 102:
  
  
=SmartCheck Update History=
 
  
Changes to the SmartCheck logic can be tracked using the Update History feature, which is available against each configured SmartCheck validation.  
+
=SmartCheck Update History=
 +
Changes to the SmartCheck logic can be tracked using the Update History feature, which is available against each configured SmartCheck validation.
  
 
[[Image:SmartCheckHistory.png]]
 
[[Image:SmartCheckHistory.png]]
  
  
If user clicks on the Update History button then are presented with an overview of all changes made to that specific SmartCheck validation, including date and time and the person who made the change.  
+
If user clicks on the Update History button then are presented with an overview of all changes made to that specific SmartCheck validation, including date and time and the person who made the change.
 
[[Image:SmartCheckHistory2.png|600px]]
 
[[Image:SmartCheckHistory2.png|600px]]
  
  
Users can also compare versions by checking the box on the left of the list view and then clicking on the Compare button.  
+
Users can also compare versions by checking the box on the left of the list view and then clicking on the Compare button.
 
[[Image:SmartCheckHistory3.png|500px]]
 
[[Image:SmartCheckHistory3.png|500px]]
  
Line 122: Line 122:
  
 
=SmartCheck Validation Structure=
 
=SmartCheck Validation Structure=
 
 
Each SmartCheck Validation statement shares the following structure:
 
Each SmartCheck Validation statement shares the following structure:
  
* '''If''' Statement (condition to be tested)<br />
+
* '''If''' Statement (condition to be tested)
* '''Result''' (assigned result based on the condition)<br />
+
* '''Result''' (assigned result based on the condition)
* '''Message''' (to be displayed when result is false)<br />
+
* '''Message''' (to be displayed when result is false)
  
  
 
In the example below:
 
In the example below:
  
<pre>if(ssParseNum(form.getStr("cf_Store Value")) > 5)
+
<pre>if(ssParseNumFromCurrency(form.getStr("cf_myCADcurrency"),"@sslocale@",1,true) > 5) {
     {result.isPassed=false;
+
    result.isPassed=false;
     result.addMsg('Some message here');
+
     result.addMsg("Some message here");
  }
+
}
</pre>
+
if(ssParseNumFromCurrency(form.getStr("cf_myDKKcurrency"),"da-DK",1,true) > 5) {
 +
    result.isPassed=false;
 +
     result.addMsg("Some message here");
 +
}</pre>
 +
 
 +
If custom field is a currency and the format will change based on different locales, use ssParseNumFromCurrency(value,locale,getnumtype,emptyok):
 +
 
 +
- "@sslocale@" returns the logged in user's locale, e.g. "fr-CA"
 +
 
 +
- getnumtype: 1=real number (10000,78 becomes 10000.78), 2=formatted currency (10000,78)
 +
 
 +
- emptyok: field can be empty
 +
 
 +
Example:  ssParseNumFromCurrency("10000,78","fr-CA",1,true) will return 10000.78
 +
 
 +
<pre>if(ssParseNumFromCurrency(form.getStr("cf_myCADcurrency"),"@sslocale@",1,true) > 5) {
 +
    result.isPassed=false;
 +
    result.addMsg("Some message here");
 +
}</pre>
 +
For other currencies with format regardless of user's locale, such as DKK, it can be implemented as:<br /> ssParseNumFromCurrency(value,getLocalestrByCurrency('DKK'),1,true) OR ssParseNumFromCurrency(value,"da-DK",1,true)<br />''(getLocalestrByCurrency will get the "default" locale of the currency code)''
 +
 
 +
<pre>if(ssParseNumFromCurrency(form.getStr("cf_myDKKcurrency"),"da-DK",1,true) > 5) {
 +
    result.isPassed=false;
 +
    result.addMsg("Some message here");
 +
}</pre>
  
 
Recognize the If, Result, Message structure:
 
Recognize the If, Result, Message structure:
  
<pre>
+
<pre>if(ssParseNum(form.getStr("cf_Store Value")) > 5)
if(ssParseNum(form.getStr("cf_Store Value")) > 5)
 
 
</pre>
 
</pre>
Check '''If''' the contents the of the form value (stored in the custom field named cf_Store_Value) is greater than 5,  
+
Check '''If''' the contents the of the form value (stored in the custom field named cf_Store_Value) is greater than 5,
<pre>{result.isPassed=false;
+
 
 +
<pre>result.isPassed=false;
 
</pre>
 
</pre>
 
Assign the value of the '''Result''' to '''"false"''' and print the custom message below.
 
Assign the value of the '''Result''' to '''"false"''' and print the custom message below.
<pre>
+
 
result.addMsg('Some message here');
+
<pre>result.addMsg("Some message here");
}
 
 
</pre>
 
</pre>
  
Line 160: Line 182:
 
<pre>if(form.getStr("sf_Application Name") == "")</pre>
 
<pre>if(form.getStr("sf_Application Name") == "")</pre>
  
 
+
Here is how it looks when you call the Stored Value for the same standard field:
Here is how it looks when you call the Stored Value for the same standard field:  
 
  
 
<pre>if("@Application Name@" == "")</pre>
 
<pre>if("@Application Name@" == "")</pre>
  
 +
Notice the stored value calls the field using the variable syntax we learned in the variable processor lesson.
  
Notice the stored value calls the field using the variable syntax we learned in the variable processor lesson.
 
  
  
Line 175: Line 196:
 
Here is how it looks when you call a system message:
 
Here is how it looks when you call a system message:
  
<pre>result.addMsg('Your message goes here.'); }</pre>
+
<pre>result.addMsg("Your message goes here.");</pre>
  
 +
Here is how it looks when you call a Field message on a custom field:
  
 +
<pre>result.addMsg("cf_@field name.id@", "Your message goes here.");</pre>
  
Here is how it looks when you call a Field message on a custom field:
+
Notice the field name is added before your message, so the system knows where to place the validation message, and the system knows where to bring your cursor should you click the message.
 +
 
 +
=Configuring Messages for Multilingual Systems=
 +
Messages can also be displayed in different languages based on the user's language of choice within the portal. The langid variable for the language must be included within the syntax to tie the message to a particular language setting.
 +
 
 +
 
 +
The message below would only be shown for the English language:
 +
 
 +
<pre>result.addMsg("Your message goes here.", 1);</pre>
 +
 
 +
The langid could also be used for Field messages:
  
<pre>result.addMsg('cf_@field name.id@', 'Your message goes here.); }</pre>
+
<pre>result.addMsg("cf_@field name.id@", "Your message goes here.", 1); </pre>
  
 +
And the following is an example with multiple languages:
  
Notice the field name is added before your message, so the system knows where to place the validation message, and the system knows where to bring your cursor should you click the message.
+
<pre>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);
 +
}</pre>
  
 +
'''Important:''' The langid variable cannot be selectively applied to the messages, it must be included in every SmartCheck message within the system.
  
 
=Examples=
 
=Examples=
 
===Check an amount is greater than $100,000===
 
===Check an amount is greater than $100,000===
<pre>if(ssParseNum(form.getStr("cf_Amount Requested")) > 100000)
+
<pre>if(ssParseNum(form.getStr("cf_Amount Requested")) > 100000) {
{result.isPassed=false;
+
    result.isPassed=false;
        result.addMsg('cf_@Amount Requested.id@','Amount Requested cannot exceed $100,000');
+
    result.addMsg("cf_@Amount Requested.id@","Amount Requested cannot exceed $100,000");
}</pre>
+
}</pre>
  
 
===Application Name field blank===
 
===Application Name field blank===
<pre>if(form.getStr("sf_Application Name") == "")
+
<pre>if(form.getStr("sf_Application Name") == ""){   
     {result.isPassed=false;
+
     result.isPassed=false;
     result.addMsg('Application name cannot be blank');
+
     result.addMsg("Application name cannot be blank");
    }</pre>
+
}</pre>
  
 
===Requested Amount less than X===
 
===Requested Amount less than X===
<pre>if(ssParseNum(form.getStr("cf_Requested Amount")) < "5000")
+
<pre>if(ssParseNum(form.getStr("cf_Requested Amount")) < 5000) {   
    {result.isPassed=false;
+
      result.isPassed=false;
    result.addMsg('cf_@Requested Amount.id@','Field test message');
+
      result.addMsg("cf_@Requested Amount.id@","Field test message");
    }</pre>
+
}</pre>
  
 
===Number value greater than 5===
 
===Number value greater than 5===
<pre>if(ssParseNum(form.getStr("cf_Store Value")) > 5)
+
<pre>if(ssParseNum(form.getStr("cf_Store Value")) > 5) {
     {result.isPassed=false;
+
     result.isPassed=false;
     result.addMsg('Some message here');
+
     result.addMsg("Some message here");
    }
+
}</pre>
</pre>
 
  
 
===Single field upload field has no file===
 
===Single field upload field has no file===
<pre>if("@Single File Field.filename@" == "")
+
<pre>if("@Single File Field.filename@" == "")
     {result.isPassed=false;
+
     result.isPassed=false;
     result.addMsg('Please upload a file here');
+
     result.addMsg("Please upload a file here");
    }
+
}</pre>
</pre>
 
  
 
===Multi file upload field has no files===
 
===Multi file upload field has no files===
<pre>if(ssParseNum("@level1.MUlti upload.numoffiles@") < 1)
+
<pre>if(ssParseNum("@level1.MUlti upload.numoffiles@") < 1) {   
     {result.isPassed=false;
+
     result.isPassed=false;
     result.addMsg('Please upload at least one file');
+
     result.addMsg("Please upload at least one file");
     }</pre>
+
}</pre>
 +
 
 +
===Dynamic XML field has no entries===
 +
<pre>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.");
 +
}</pre>
  
 
===Comparing two custom date fields with separate custom time fields storing 24 hour time===
 
===Comparing two custom date fields with separate custom time fields storing 24 hour time===
<pre>if(form.getStr("cf_Event Start Date")+' '+form.getStr("cf_Event Start Time") >= form.getStr("cf_Event End Date")+' '+form.getStr("cf_Event End Time"))
+
<pre>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.isPassed=false;
     result.addMsg('cf_@Event End Time.id@','End Time must take place after the Start Time');
+
     result.addMsg("cf_@Event End Time.id@","End Date must take place after the Start Date");
    }</pre>
+
}</pre>
 
 
  
 
===Comparing a date custom field to the current date===
 
===Comparing a date custom field to the current date===
<pre>
+
<pre>if ((ssConvertDate(form.getStr("cf_Individual Review Start Date"), "@dateformat@", "yyyy-mm-dd") > "@date(currentdate)@")) {
if ((ssConvertDate(form.getStr("cf_Individual Review Start Date"), "@dateformat@", "yyyy-mm-dd") > "@date(currentdate)@"))  
+
    result.isPassed = false;
  {result.isPassed = false;
+
     result.addMsg("cf_@Individual Review Start Date.id@", "Please enter a date less than or equal to today for the date.");
     result.addMsg('cf_@Individual Review Start Date.id@', 'Please enter a date less than or equal to today for the date.');
+
}</pre>
}
 
</pre>
 
  
 
===Comparing a date custom field to a date that is six months ago (date must be at least six months ago)===
 
===Comparing a date custom field to a date that is six months ago (date must be at least six months ago)===
<pre>
+
<pre>if(ssConvertDate(form.getStr("cf_Date"),"@dateformat@", "yyyy-mm-dd") > "<!--@sscalculation(DATE_ADD('@date(currentdate)@', INTERVAL -6 MONTH))-->"){
if(ssConvertDate(form.getStr("cf_Date"),"@dateformat@", "yyyy-mm-dd") > "<!--@sscalculation(DATE_ADD('@date(currentdate)@', INTERVAL -6 MONTH))-->")
+
    result.isPassed=false;
  {result.isPassed=false;
+
    result.addMsg("cf_@Date.id@","Date must be at least 6 months prior to today's date");
  result.addMsg('cf_@Date.id@','Date must be at least 6 months prior to today's date');
+
}</pre>
  }</pre>
+
NOTE: When using @sscalculation, you <u>must</u> wrap the syntax in double quotes
 +
 
 +
===Comparing two date custom fields which also store time===
 +
<pre>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');
 +
}</pre>
 +
 
 +
===Ensuring an entered date is at least 3 business days away===
 +
<pre>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");
 +
}</pre>
 +
NOTE: When using @sscalculation, you <u>must</u> wrap the syntax in double quotes
  
 
===Date custom field blank===
 
===Date custom field blank===
<pre>
+
<pre>if ((ssConvertDate(form.getStr("cf_Project Start Date"), "@dateformat@", "yyyy-mm-dd") == "")) {
if ((ssConvertDate(form.getStr("cf_Project Start Date"), "@dateformat@", "yyyy-mm-dd") == "yyyy-mm-dd"))  
+
    result.isPassed = false;
  {result.isPassed = false;
+
    result.addMsg("cf_@Project Start Date.id@", "Project Start Date is a required field.");
  result.addMsg('cf_@Project Start Date.id@', 'Project Start Date is a required field.');
+
}</pre>
  }</pre>
 
 
 
  
 
===Validation on a Select Many Checkbox Field===
 
===Validation on a Select Many Checkbox Field===
<pre>if(form.getStr("cf_Request Type").indexOf("General Operating")==-1 )
+
<pre>if(form.getStr("cf_Request Type").indexOf("General Operating")==-1 ) {
  {result.isPassed=false;
+
    result.isPassed=false;
  result.addMsg('General Operating was not selected');
+
    result.addMsg("General Operating was not selected");
  }</pre>
+
}</pre>
 
To trigger when the value is selected, use '!=-1'. This would normally be used in combination with another field for validations.
 
To trigger when the value is selected, use '!=-1'. This would normally be used in combination with another field for validations.
 +
 +
===Select Many Checkbox field has at least 5 values selected===
 +
<pre>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.");
 +
}</pre>
  
 
===At least one role is selected on a contact===
 
===At least one role is selected on a contact===
<pre>if('@rolelist@' == "")
+
<pre>if("@rolelist@" == "") {
{result.isPassed=false;
+
    result.isPassed=false;
result.addMsg('At least one role must be selected.');
+
    result.addMsg("At least one role must be selected.");
        }</pre>
+
}</pre>
  
 
===Validation on an e-mail field===
 
===Validation on an e-mail field===
<pre>if(!isEmail(form.getStr("cf_Additional Email 1")))
+
<pre>if(!isEmail(form.getStr("cf_Additional Email 1"))) {
{result.isPassed=false;
+
    result.isPassed=false;
result.addMsg('cf_@Additional Email 1.id@','Please enter a valid e-mail address.');
+
    result.addMsg("cf_@Additional Email 1.id@","Please enter a valid e-mail address.");
}</pre>
+
}</pre>
 +
 
 +
===Validate that the status of the organization is Active===
 +
<pre>if("@client.status@" != "Active") {
 +
    result.isPassed=false;
 +
    result.addMsg("Please update your Organization Profile then return to this record and click Submit Application.");
 +
}</pre>
 +
 
 +
===Validation on a Note Enabled Multiple-Line custom field===
 +
When validating against a Note Enabled field, within the result.addMsg() alert you will need to include '''h''' in-front of the custom field reference.
 +
 
 +
<pre>if(form.getStr("cf_notefield")=="") {
 +
    result.isPassed= false;
 +
    result.addMsg("cf_h@notefield.id@","You must type in a description before submitting for revisions.");
 +
}</pre>
 +
 
 +
===Minimum word count limit===
 +
Used on multiline text fields to limit the minimum word entry
 +
 
 +
<pre>if(form.getStr("cf_Leadership").split(' ').length < 100) {<br />    result.isPassed=false;<br />    result.addMsg("cf_@Leadership.id@","Leadership question must have minimum 100 words");<br />}</pre>
 +
 
 +
===Count contacts in a specific role===
 +
Used to ensure at least one contact is attached to the record in a specific role
 +
 
 +
<pre>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.");
 +
}</pre>
 +
 
 +
===Defining VAR Variables===
 +
Using var javascript variables to define values to be evaluated within the SmartCheck Validation.
 +
 
 +
<pre>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.");
 +
}
 +
</pre>
 +
 
 +
===Application Limit Check via Specific Criteria===
 +
Validating an application via a custom field on the form and pulling that into report criteria.
 +
 
 +
<pre>var maxstores="TEST@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");
 +
}</pre>
  
===To include other scripts into a SmartCheck script:===
+
==To include other scripts into a SmartCheck script:==
 
<pre>//@include(AnotherSmartCheckScriptName)@
 
<pre>//@include(AnotherSmartCheckScriptName)@
 
</pre>
 
</pre>
  
 +
==Validating Currency Fields with Formatting Enabled:==
 +
Please see [[SsParseNum|ssParseNum: When Using Show Currency Format in Edit Mode]]
  
 
==See Also==
 
==See Also==

Latest revision as of 08:22, 1 October 2024

Contents

Overview

SmartCheck Validation is a secure server side validation method. It enables custom field validation ensuring that applications and form inputs meets specified criteria and returns. It provides a better user experience than other validation methodologies and is preferred over Submit Logic. With SmartCheck, the user can see error messages in context and in one central place.

Before SmartCheck Validation, some error message would pop up individually, one after another, and some messages would appear in one box at the top, depending on how you setup your validation.

Smartcheck validationOLD.png


With SmartCheck Validation and the message type of Field, you will see all messages in one central spot as well as in context messages. See image below.


Smartcheck validation1.png

Clicking on the x within the in context error message, such as the description field above, enables you to temporarily hide the message. Clicking the error message at the top will bring the cursor to the field where the error is present (if there is a corresponding input). The context error message will also disappear when you have modified the value within field in question.


Before you can use SmartCheck validation you must . . .

1. Configure SmartCheck Validation

2. Add SmartCheck Validation to Submit Button

3. Enable SmartCheck Validation

Note that once you turn on SmartCheck Validation it is enabled everywhere. If you already set up submit logic or other validation before you turned on SmartCheck validation, you will need to test your validation to ensure it works as expected and or replace it with SmartCheck validation.


Configure SmartCheck Validation

SmartCheck Validation can be configured for each object type in the system (i.e. individual UTA Level 1/2/3, company, user, transaction) and then be attached to a Submit button.


1. Each entity will have a SmartCheck Validation link available in the corresponding Settings page. Click on this to begin the process of configuring the SmartCheck validation statements.

SmartCheck1.png


2. The Smartcheck Validation list view will display. There will be a New Validation button along the top. Click this. SmartCheckLV.png

3. The SmartCheck validation screen will display, comprised of the following 3 tabs . . .

  • Main
  • Code Builder
  • Source


4. Enter appropriate name and description text into the relevant fields on the Main tab and click Save.

SmartCheck2.png


5. Navigate to the Code Builder tab to add validation using 2 possible approaches.

  • New validation: Use the drop-downs at the top of the screen to create new validation. Further details on the options available are provided in the SmartCheck Validation Structure section below.

SmartCheck3.png


  • Existing Submit Logic: Use the drop-down at the bottom of the screen to select a submit button and any existing validation associated with this button.

SmartCheck4.png


6. Click on the Insert button under the relevant section. This will take you to the Source tab, and show the updated validation statement.

SmartCheck5.png


7. Click the Save button to store all changes.

8. Use the Trial Run at the bottom of the Source tab to check whether there are errors when the validation statements run.


Add SmartCheck Validation to Submit Button

Once the validation statements are created you can start to add the logic to Submit or Save buttons.

1. Each entity will have a [Submit & Save Buttons]] link available in the corresponding Settings page. Click on this to begin the process of adding the SmartCheck validation statements to a button.

Submit and save button1.png


2. The Submit & Save Buttons page is displayed, showing a list of configured buttons. Click on the Edit button for the one you wish to edit.


3. Select the SmartCheck Validation option from the corresponding drop-down

SmartCheck6.png


4. Click Save at the bottom of the page.


Enable SmartCheck Validation

  1. In the top header, click the Configuration drop down.
  2. Select Global Settings.
  3. On the first tab called System, Check the box beside Activate SmartCheck Validation.
  4. Click Save.


SmartCheck Update History

Changes to the SmartCheck logic can be tracked using the Update History feature, which is available against each configured SmartCheck validation.

SmartCheckHistory.png


If user clicks on the Update History button then are presented with an overview of all changes made to that specific SmartCheck validation, including date and time and the person who made the change. SmartCheckHistory2.png


Users can also compare versions by checking the box on the left of the list view and then clicking on the Compare button. SmartCheckHistory3.png


Users will be presented with screen showing differences between the 2 versions.

SmartCheckHistory4.png

SmartCheck Validation Structure

Each SmartCheck Validation statement shares the following structure:

  • If Statement (condition to be tested)
  • Result (assigned result based on the condition)
  • Message (to be displayed when result is false)


In the example below:

if(ssParseNumFromCurrency(form.getStr("cf_myCADcurrency"),"@sslocale@",1,true) > 5) {
    result.isPassed=false;
    result.addMsg("Some message here");
}
if(ssParseNumFromCurrency(form.getStr("cf_myDKKcurrency"),"da-DK",1,true) > 5) {
    result.isPassed=false;
    result.addMsg("Some message here");
}

If custom field is a currency and the format will change based on different locales, use ssParseNumFromCurrency(value,locale,getnumtype,emptyok):

- "@sslocale@" returns the logged in user's locale, e.g. "fr-CA"

- getnumtype: 1=real number (10000,78 becomes 10000.78), 2=formatted currency (10000,78)

- emptyok: field can be empty

Example:  ssParseNumFromCurrency("10000,78","fr-CA",1,true) will return 10000.78

if(ssParseNumFromCurrency(form.getStr("cf_myCADcurrency"),"@sslocale@",1,true) > 5) {
    result.isPassed=false;
    result.addMsg("Some message here");
}

For other currencies with format regardless of user's locale, such as DKK, it can be implemented as:
ssParseNumFromCurrency(value,getLocalestrByCurrency('DKK'),1,true) OR ssParseNumFromCurrency(value,"da-DK",1,true)
(getLocalestrByCurrency will get the "default" locale of the currency code)

if(ssParseNumFromCurrency(form.getStr("cf_myDKKcurrency"),"da-DK",1,true) > 5) {
    result.isPassed=false;
    result.addMsg("Some message here");
}

Recognize the If, Result, Message structure:

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

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

result.isPassed=false;

Assign the value of the Result to "false" and print the custom message below.

result.addMsg("Some message here");

Form Value vs Stored Value

In the SmartCheck code builder there is a select where you choose between Form Value and Stored Value. The Form Value' is the value someone has entered into his or her application (form), this includes information that has not been saved. The Stored Value is the value from the server (information that has been saved). By using the Form Value you can validate based on information that the user has entered into the form even if they have not clicked save on their application.


Here is how it looks when you call the Form Value for a standard field:

if(form.getStr("sf_Application Name") == "")

Here is how it looks when you call the Stored Value for the same standard field:

if("@Application Name@" == "")

Notice the stored value calls the field using the variable syntax we learned in the variable processor lesson.


Field vs System Messages

In the SmartCheck code builder there is a select where you can choose between Field and System Messages. Field messages appear both at the top of the application and on the field that failed validation, this type is recommended for most validations. System messages appear only at the top of the application. You might use System messages when your validation compares more than one field, as it may not be obvious which field to highlight with the error message.


Here is how it looks when you call a system message:

result.addMsg("Your message goes here.");

Here is how it looks when you call a Field message on a custom field:

result.addMsg("cf_@field name.id@", "Your message goes here.");

Notice the field name is added before your message, so the system knows where to place the validation message, and the system knows where to bring your cursor should you click the message.

Configuring Messages for Multilingual Systems

Messages can also be displayed in different languages based on the user's language of choice within the portal. The langid variable for the language must be included within the syntax to tie the message to a particular language setting.


The message below would only be shown for the English language:

result.addMsg("Your message goes here.", 1);

The langid could also be used for Field messages:

result.addMsg("cf_@field name.id@", "Your message goes here.", 1); 

And the following is an 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);
}

Important: The langid variable cannot be selectively applied to the messages, it must be included in every SmartCheck message within the system.

Examples

Check an amount is greater than $100,000

if(ssParseNum(form.getStr("cf_Amount Requested")) > 100000) {
    result.isPassed=false;	
    result.addMsg("cf_@Amount Requested.id@","Amount Requested cannot exceed $100,000");
}

Application Name field blank

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

Requested Amount less than X

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

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

Single field upload field has no file

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

Multi file upload field has no files

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

Dynamic XML field has no entries

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.");
}

Comparing two custom date fields with separate custom 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");
}

Comparing a date custom 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.");
}

Comparing a date custom field to a date that is six months ago (date must be at least six months ago)

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");
}

NOTE: When using @sscalculation, you must wrap the syntax in double quotes

Comparing two date custom fields which 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');
}

Ensuring an entered date is at least 3 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");
}

NOTE: When using @sscalculation, you must wrap the syntax in double quotes

Date custom field blank

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.");
}

Validation on a Select Many Checkbox Field

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 would normally be used in combination with another field for validations.

Select Many Checkbox field has at least 5 values selected

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.");
}

At least one role is selected on a contact

if("@rolelist@" == "") {
    result.isPassed=false;
    result.addMsg("At least one role must be selected.");
}

Validation on an e-mail field

if(!isEmail(form.getStr("cf_Additional Email 1")))	{
    result.isPassed=false;
    result.addMsg("cf_@Additional Email 1.id@","Please enter a valid e-mail address.");
}

Validate that the status of the organization 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.");	
}

Validation on a Note Enabled Multiple-Line custom field

When validating against a Note Enabled field, within the result.addMsg() alert you will need to include h in-front of the custom field reference.

if(form.getStr("cf_notefield")=="") {
    result.isPassed= false;
    result.addMsg("cf_h@notefield.id@","You must type in a description before submitting for revisions.");
}

Minimum word count limit

Used on multiline text fields to limit the minimum word entry

if(form.getStr("cf_Leadership").split(' ').length < 100) {<br />    result.isPassed=false;<br />    result.addMsg("cf_@Leadership.id@","Leadership question must have minimum 100 words");<br />}

Count contacts in a specific role

Used to ensure at least one contact is attached to the record 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."); 
}

Defining VAR Variables

Using var javascript variables to define values to be evaluated within the SmartCheck Validation.

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.");
}

Application Limit Check via Specific Criteria

Validating an application via a custom field on the form and pulling that into report criteria.

var maxstores="TEST@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");
}

To include other scripts into a SmartCheck script:

//@include(AnotherSmartCheckScriptName)@

Validating Currency Fields with Formatting Enabled:

Please see ssParseNum: When Using Show Currency Format in Edit Mode

See Also