Changes

SmartCheck Validation

No change in size, 20:26, 15 February 2023
no edit summary
<pre>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'");
}</pre>
<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>
Assign the value of the '''Result''' to '''"false"''' and print the custom message below.
<pre>result.addMsg('"Some message here'");
</pre>
Here is how it looks when you call a system message:
<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>
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.
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.'", 1); </pre>
And the following is an example with multiple languages:
<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>
<pre>if(ssParseNum(form.getStr("cf_Amount Requested")) > 100000) {
result.isPassed=false;
result.addMsg("cf_@Amount Requested.id@",'"Amount Requested cannot exceed $100,000'");
}</pre>
<pre>if(form.getStr("sf_Application Name") == ""){
result.isPassed=false;
result.addMsg('"Application name cannot be blank'");
}</pre>
<pre>if(ssParseNum(form.getStr("cf_Requested Amount")) < 5000) {
result.isPassed=false;
result.addMsg("cf_@Requested Amount.id@",'"Field test message'");
}</pre>
<pre>if(ssParseNum(form.getStr("cf_Store Value")) > 5) {
result.isPassed=false;
result.addMsg('"Some message here'");
}</pre>
<pre>if("@Single File Field.filename@" == "") {
result.isPassed=false;
result.addMsg('"Please upload a file here'");
}</pre>
<pre>if(ssParseNum("@level1.MUlti upload.numoffiles@") < 1) {
result.isPassed=false;
result.addMsg('"Please upload at least one file'");
}</pre>
<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>
<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.addMsg("cf_@Event End Time.id@",'"End Date must take place after the Start Date'");
}</pre>
<pre>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.'");
}</pre>
<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
<pre>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.'");
}</pre>
<pre>if(form.getStr("cf_Request Type").indexOf("General Operating")==-1 ) {
result.isPassed=false;
result.addMsg('"General Operating was not selected'");
}</pre>
To trigger when the value is selected, use '!=-1'. This would normally be used in combination with another field for validations.
<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>
<pre>if("@rolelist@" == "") {
result.isPassed=false;
result.addMsg('"At least one role must be selected.'");
}</pre>
<pre>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.'");
}</pre>
<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>
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===
if(countWatch=="0") {
result.isPassed=false;
result.addMsg('"Please run a watchlist scan.'");
}
</pre>
if(y!=-1) {
result.isPassed=false;
result.addMsg("cf_@txt_StoreNumber.id@",'"Test'");
}</pre>
Smartstaff
4
edits