Difference between revisions of "SSlogic"

From SmartWiki
Jump to: navigation, search
 
(15 intermediate revisions by 6 users not shown)
Line 1: Line 1:
 
[[Web Page View Field|Web Page View]] fields can use a unique [[SmartSimple]] logic interpreter. Web page logic gives you the ability to display certain content or perform certain actions only when specified conditions are met.
 
[[Web Page View Field|Web Page View]] fields can use a unique [[SmartSimple]] logic interpreter. Web page logic gives you the ability to display certain content or perform certain actions only when specified conditions are met.
 
[[SmartSimple]] logic uses the following syntax:
 
[[SmartSimple]] logic uses the following syntax:
 +
 
<pre>
 
<pre>
 
<!--@sslogic(CONDITION)-->
 
<!--@sslogic(CONDITION)-->
Line 10: Line 11:
 
* The content to be displayed (the middle line) can either be in plaintext or in HTML.
 
* The content to be displayed (the middle line) can either be in plaintext or in HTML.
 
* Be sure there are quotes (single or double) around the variable and value. Note: Your choice in the use of quotes depends on the variable's contents. E.g. names containing apostrophes should use double quotes when referencing that variable.
 
* Be sure there are quotes (single or double) around the variable and value. Note: Your choice in the use of quotes depends on the variable's contents. E.g. names containing apostrophes should use double quotes when referencing that variable.
* SSlogic does not support nested logic statements.  
+
* SSlogic does not support nested logic statements. In other words, you cannot put an sslogic statement within another sslogic statement.
 +
* NOTE: You cannot use sscalculation syntax within an sslogic statement. The sslogic syntax will manage the calculating. It does not require additional syntax prompts.
  
  
 
'''Example:'''
 
'''Example:'''
 +
 
* The following will display a Christmas tree image if the month is December:
 
* The following will display a Christmas tree image if the month is December:
 +
 
<pre>
 
<pre>
 
<!--@sslogic(month(now())=12)-->
 
<!--@sslogic(month(now())=12)-->
   <img src='images/xmasstree.jpg'>
+
   <img src="images/xmasstree.jpg" alt="" />
 
<!--@end-->
 
<!--@end-->
 
</pre>
 
</pre>
Line 23: Line 27:
 
* Precede the equal sign with an exclamation point to test for '''Not Equal'''
 
* Precede the equal sign with an exclamation point to test for '''Not Equal'''
 
* The following will display a message for all provinces except Ontario:
 
* The following will display a message for all provinces except Ontario:
 +
 
<pre>
 
<pre>
 
<!--@sslogic("@province@"!="Ontario")-->
 
<!--@sslogic("@province@"!="Ontario")-->
Line 29: Line 34:
 
</pre>
 
</pre>
  
'''Else Logic:'''
+
==Else Logic==
 
* Often, you will want to display one of two texts--one text in the case that a condition is met and another in the case that the condition is not met. This is achieved through the use of an "else" operator.
 
* Often, you will want to display one of two texts--one text in the case that a condition is met and another in the case that the condition is not met. This is achieved through the use of an "else" operator.
 
* The following sample code will display one message if a user is male and another if the user is female:
 
* The following sample code will display one message if a user is male and another if the user is female:
 +
 
<pre>
 
<pre>
<!--@sslogic("@sex@"="M")-->
+
<!--@sslogic(@age@>=18)-->
   You are a guy.
+
   Person is an adult.
 
<!--@else-->
 
<!--@else-->
  You are a girl.
+
  Person is a minor.
 
<!--@end-->
 
<!--@end-->
 
</pre>
 
</pre>
  
 
* The following will display 2 check boxes. If the gender is male the first check box (Male) will be ticked. If the gender is female the second check box will be ticked:
 
* The following will display 2 check boxes. If the gender is male the first check box (Male) will be ticked. If the gender is female the second check box will be ticked:
 +
 
<pre>
 
<pre>
<!--@sslogic('@parent.owner.clientgender@'='Male')-->
+
<!--@sslogic(@parent.owner.age@>=18)-->
   <input type="checkbox" checked> Male
+
   <input checked="checked" type="checkbox" /> Adult
   <input type="checkbox"> Female
+
   <input type="checkbox" /> Minor
 
<!--@else-->
 
<!--@else-->
   <input type="checkbox"> Male
+
   <input type="checkbox" /> Adult
   <input type="checkbox" checked> Female
+
   <input checked="checked" type="checkbox" /> Minor
 
<!--@end-->
 
<!--@end-->
 
</pre>
 
</pre>
  
'''Multiple Options:'''
+
==Multiple Options ("else if" syntax):==
You can use multiple sslogic statements if there are more than just 2 options:
+
You can use multiple "else if" operators if there are more than just 2 options:
<pre>
+
 
<!--@sslogic("@possibility@"="Yes")-->
+
<nowiki><!--@sslogic(</nowiki>''condition 1'')-->aaa
  This will happen for certain.
+
  <nowiki><!--@else if(</nowiki>''condition 2'')-->bbb
<!--@end-->
+
              <nowiki><!--@else if(</nowiki>''condition 3'')-->ccc
 +
              <nowiki><!--@else-->ddd </nowiki>
 +
<nowiki><!--@end--></nowiki></nowiki></nowiki></nowiki>
  
<!--@sslogic("@possibility@"="No")-->
+
'''Example:'''
  This is not happening.
 
<!--@end-->
 
  
<!--@sslogic('@possibility@'='Maybe')-->
+
<pre><!--@sslogic("@possibility@"="Yes")-->
 +
  This will happen for certain.
 +
<!--@else if("@possibility@"="No")-->
 +
  This is not happening.
 +
<!--@else if("@possibility@"="Maybe")-->
 
   This may or may not happen.
 
   This may or may not happen.
<!--@end-->
+
<!--@else-->
</pre>
+
  No-one knows what will happen.
 +
<!--@end--></pre>
  
 +
<!--per support ticket 17150 - Else if for sslogic -->
 +
==Multiple Conditions==
 +
* You can include more than one condition:
  
'''Multiple Conditions:'''
 
* You can include more than one condition:
 
 
<pre>
 
<pre>
 
<!--@sslogic('@year@'='2008' AND  ('@month@'='1' OR '@month@'='2'))-->
 
<!--@sslogic('@year@'='2008' AND  ('@month@'='1' OR '@month@'='2'))-->
Line 76: Line 89:
 
</pre>
 
</pre>
  
'''Fields Storing Single Quotes:'''
+
==Fields Storing Single Quotes or Double Quotes==
* SSlogic can be used to display fields that may have a single quote stored within them.  
+
* SSlogic can be used to display fields that may have single quotes or double quotes stored within them.
 
* The escape[] function is used to achieve this:
 
* The escape[] function is used to achieve this:
 +
 +
<pre><nowiki><!--@sslogic('escape["23456$]'!='')--></nowiki>
 +
</pre>
 +
<pre><nowiki><!--@sslogic('escape[@Field Name@]'!='')--></nowiki>
 +
</pre>
 +
* NOTE: You must wrap the function using single quotes
 +
 +
==Using Object Lists==
 +
* Object [[Web_Page_View_Field_Variables#List|Lists]] can also be used in SSlogic.
 +
 
<pre>
 
<pre>
<!--@sslogic('escape[$1137762$]'!='')-->
+
<!--@sslogic("[#(?object=contact::criteria=rolename='Supervisor'::groupfunction=count)~userid~#]">0)-->
 +
  There is at least one Supervisor
 +
<!--@else-->
 +
  There are no Supervisors
 +
<!--@end-->
 
</pre>
 
</pre>
  
 
+
==Using With SSattach==
 
* SSlogic can be used to determine which pdf file is appended to the Web Page View using '''ssattach'''
 
* SSlogic can be used to determine which pdf file is appended to the Web Page View using '''ssattach'''
 
* The following example will attach ''myfilefooter.pdf'' if the Type/Template is Contract, and ''myotherfilefooter.pdf'' if not:
 
* The following example will attach ''myfilefooter.pdf'' if the Type/Template is Contract, and ''myotherfilefooter.pdf'' if not:
 +
 
<pre>
 
<pre>
<!--@sslogic('@type@'='Contract') -->
+
<!--@sslogic("@type@"="Contract")-->
      <!--@ssattach(after;/files/1234/123/myfilefooter.pdf )-->
+
    <!--@ssattach(after;/files/1234/123/myfilefooter.pdf)-->
 
<!--@else-->
 
<!--@else-->
     <!-- @ssattach(after;/files/1234/123/myotherfilefooter.pdf )-->
+
     <!--@ssattach(after;/files/1234/123/myotherfilefooter.pdf )-->
 
<!--@end-->
 
<!--@end-->
 
</pre>
 
</pre>
::'''''Note:''' ssattach can be used without sslogic if you want the same pdf file attached to the Web Page View in all cases.''
+
:: '''''Note:''' [[ssattach]] can be used without sslogic if you want the same pdf file attached to the Web Page View in all cases.''
 
+
==Notes==
==Note==
+
* SSlogic can be used in workflow e-mails at Level 1 only.
* sslogic can be used in workflow e-mails at Level 1 only.
+
* In general, double quotes (") should be used to enclose variables rather than single quotes ('). If the content includes an apostrophe (equivalent to a single quote) it will disrupt the processing. Double quotes are less common as content. You may want to add an [[Removing Special Characters|onchange]] to the source field to prevent entry of double quotes.
* In general double quotes (") should be used to enclose variables rather than single quotes ('). If the content includes an apostrophe (equivalent to a single quote) it will disrupt the processing. Double quotes are less common as content. You may want to add an [[Removing Special Characters|onchange]] to the source field to prevent entry of double quotes.
 
  
 
==See Also==
 
==See Also==
 
* [[Web Page View Field]]
 
* [[Web Page View Field]]
 
* [[Web Page View Field Variables]]
 
* [[Web Page View Field Variables]]
 +
* [[sscalculation]]
  
  
 
[[Category:Custom Fields]][[Category:Variables]]
 
[[Category:Custom Fields]][[Category:Variables]]

Latest revision as of 15:28, 21 April 2021

Web Page View fields can use a unique SmartSimple logic interpreter. Web page logic gives you the ability to display certain content or perform certain actions only when specified conditions are met. SmartSimple logic uses the following syntax:

<!--@sslogic(CONDITION)-->
   The content to be displayed when condition is true.
   This can be more than one line.
<!--@end-->
  • The content to be displayed (the middle line) can either be in plaintext or in HTML.
  • Be sure there are quotes (single or double) around the variable and value. Note: Your choice in the use of quotes depends on the variable's contents. E.g. names containing apostrophes should use double quotes when referencing that variable.
  • SSlogic does not support nested logic statements. In other words, you cannot put an sslogic statement within another sslogic statement.
  • NOTE: You cannot use sscalculation syntax within an sslogic statement. The sslogic syntax will manage the calculating. It does not require additional syntax prompts.


Example:

  • The following will display a Christmas tree image if the month is December:
<!--@sslogic(month(now())=12)-->
   <img src="images/xmasstree.jpg" alt="" />
<!--@end-->
  • Precede the equal sign with an exclamation point to test for Not Equal
  • The following will display a message for all provinces except Ontario:
<!--@sslogic("@province@"!="Ontario")-->
   You are outside of Ontario
<!--@end-->

Else Logic

  • Often, you will want to display one of two texts--one text in the case that a condition is met and another in the case that the condition is not met. This is achieved through the use of an "else" operator.
  • The following sample code will display one message if a user is male and another if the user is female:
<!--@sslogic(@age@>=18)-->
  Person is an adult.
<!--@else-->
  Person is a minor.
<!--@end-->
  • The following will display 2 check boxes. If the gender is male the first check box (Male) will be ticked. If the gender is female the second check box will be ticked:
<!--@sslogic(@parent.owner.age@>=18)-->
   <input checked="checked" type="checkbox" /> Adult
   <input type="checkbox" /> Minor
<!--@else-->
   <input type="checkbox" /> Adult
   <input checked="checked" type="checkbox" /> Minor
<!--@end-->

Multiple Options ("else if" syntax):

You can use multiple "else if" operators if there are more than just 2 options:

<!--@sslogic(condition 1)-->aaa
 <!--@else if(condition 2)-->bbb 
              <!--@else if(condition 3)-->ccc 
              <!--@else-->ddd 
<!--@end--></nowiki></nowiki></nowiki>

Example:

<!--@sslogic("@possibility@"="Yes")-->
  This will happen for certain.
<!--@else if("@possibility@"="No")-->
  This is not happening. 
<!--@else if("@possibility@"="Maybe")-->
  This may or may not happen.
<!--@else-->
  No-one knows what will happen.
<!--@end-->

Multiple Conditions

  • You can include more than one condition:
<!--@sslogic('@year@'='2008' AND  ('@month@'='1' OR '@month@'='2'))-->
   This is only displayed if the year is 2008 and the month is either Jan or Feb.
<!--@end-->

Fields Storing Single Quotes or Double Quotes

  • SSlogic can be used to display fields that may have single quotes or double quotes stored within them.
  • The escape[] function is used to achieve this:
<!--@sslogic('escape["23456$]'!='')-->
<!--@sslogic('escape[@Field Name@]'!='')-->
  • NOTE: You must wrap the function using single quotes

Using Object Lists

  • Object Lists can also be used in SSlogic.
<!--@sslogic("[#(?object=contact::criteria=rolename='Supervisor'::groupfunction=count)~userid~#]">0)-->
   There is at least one Supervisor
<!--@else-->
   There are no Supervisors
<!--@end-->

Using With SSattach

  • SSlogic can be used to determine which pdf file is appended to the Web Page View using ssattach
  • The following example will attach myfilefooter.pdf if the Type/Template is Contract, and myotherfilefooter.pdf if not:
<!--@sslogic("@type@"="Contract")-->
     <!--@ssattach(after;/files/1234/123/myfilefooter.pdf)-->
<!--@else-->
     <!--@ssattach(after;/files/1234/123/myotherfilefooter.pdf )-->
<!--@end-->
Note: ssattach can be used without sslogic if you want the same pdf file attached to the Web Page View in all cases.

Notes

  • SSlogic can be used in workflow e-mails at Level 1 only.
  • In general, double quotes (") should be used to enclose variables rather than single quotes ('). If the content includes an apostrophe (equivalent to a single quote) it will disrupt the processing. Double quotes are less common as content. You may want to add an onchange to the source field to prevent entry of double quotes.

See Also