The Variable Processor replaces variable references, such as {{firstname}}, with actual data values, such as John, throughout SmartSimple. SmartSimple supports two variable syntax options: the original @ symbol syntax and a double curly brace syntax {{ }}. The @ symbol syntax is not compatible with the rich text editor, so the double curly brace syntax provides a compatible alternative.
Enable the New Variable Syntax
To enable the new syntax:
- Click the System Administration gear in the upper navigation bar, select Global Settings, and then click the System tab.
- Locate the System Options section, and toggle Enable New Variable Syntax Set on.
Old Syntax vs. New Syntax
The following table lists each old syntax pattern and its new equivalent.
| Old Syntax | New Syntax |
|---|---|
| @fieldname@ | {{fieldname}} |
| @fieldname.value@ | {{fieldname.value}} |
| <ssEncrypt>test</ssEncrypt> | {{ssEncrypt(test)}} |
| <ssTranslate>test</ssTranslate> | {{ssTranslate(test)}} |
| <ssEscape>test</ssEscape> | {{ssEscape(test)}} |
| <!--@sslogic(condition)--> | {{ss_if(condition)}} |
| <!--@else if(condition)--> | {{ss_elseif(condition)}} |
| <!--@else--> | {{ss_else}} |
| <!--end--> | {{ss_endif}} |
| <!--@sscalculation(expression)--> | {{ss_eval(expression)}} |
| @ssGet(...)@ | {{ssGet(...)}} |
| @system.fieldname@ | {{system.fieldname}} |
| @xml.fieldname.nodename@ | {{xml.fieldname.nodename}} |
| @parent.fieldname@ | {{parent.fieldname}} |
| @ReportProperty(...)@ | {{ReportProperty(...)}} |
| @parent.[# ... #]@ | {{parent.[# ... #]}} |
Incorrect vs. Correct Variable Usage
The following examples show common Variable Processor usage errors, the corrected pattern, and the effect of each error. All examples use the original @ symbol syntax.
Template Formulas
Template formulas can assign a value to a custom field by using variables. The following examples show how quotation marks around a string value determine whether the formula saves successfully or returns an error.
Incorrect Example
String values assigned to a custom field must be in quotes. Without quotes, the server returns an error and nothing is saved.
@level1.name@=@level1.owner.firstname@ @level1.owner.lastname@;
Incorrect Example
A name with an apostrophe, such as O'Brien, ends a single-quoted string early. The server returns an error and nothing is saved.
@level1.name@='@level1.owner.firstname@ @level1.owner.lastname@';
Correct Example
Double quotes around the string value avoid both errors. Double quotes are the safe choice for strings.
@level1.name@="@level1.owner.firstname@ @level1.owner.lastname@";
Browser Scripts
Browser scripts can reference variables, and the Variable Processor replaces those variables before the page reaches the browser. If a variable is not replaced, the leftover text breaks the script and all later scripts on the page. The following examples show how to reference variables in a browser script without causing this error.
Incorrect Example
If the field value is null, the variable may not be replaced. The unreplaced text breaks the script and all later scripts on the page.
frm.cf_@customfield.id@.value="";
Correct Example
Referencing the field with getElementById avoids the unreplaced variable text.
document.getElementById("cf_@customfield.id@");
Incorrect Example
A blank or missing variable breaks the script and all later scripts on the page.
var oppid=@opportunityid@;
Correct Example
Double quotes around the variable keep the script from breaking when the value is blank or missing.
var oppid="@opportunityid@";
Visibility Conditions
Visibility conditions can include variables whose values do not exist yet, such as the opportunity ID on a new Level 1 record. The following examples show how to write a visibility condition so it does not return an error when the variable value is missing.
Incorrect Example
A new Level 1 does not have an opportunity ID yet, so the variable is not replaced. The condition returns an error and always fails.
@opportunityid@>0
Correct Example
Double quotes and *1 cast the value to a number, so the condition no longer errors when the value is missing.
"@opportunityid@"*1>0
Calculations
Calculations can combine variable values, such as a custom number field and a report property. A blank or null value causes the calculation to return an error. The following examples show how to cast each variable to a number so the calculation still works when a value is blank.
Incorrect Example
A blank or null value causes an error.
@ReportProperty(12345,recordcount)@ + @custom number@
Correct Example
The *1 casts each value to a number and converts blank or alphabetic values to zero.
"@ReportProperty(12345,recordcount)@"*1 + "@custom number@"*1
Quoting Exceptions
Variable references in @sslogic()@ or @sscalculation()@ conditions also need quotes. Without quotes, the condition returns an error. The error can go unnoticed because the @sslogic()@ output does not show up, and the result may appear correct in some situations.
The .inRole variable always returns true or false, so it does not need double quotes, as in @me.inRole(Organization Contact)@.
When a variable value contains double quotes, escape them. Single quotes can wrap the variable instead, but only when the value is certain to contain no single quotes.
SmartSimple Order of Operations
SmartSimple runs a fixed sequence of processes when a Level 1, 2, or 3 record opens, when the record is saved, and after the save completes. Later processes can depend on the results of earlier ones, so the order affects how variables, scripts, formulas, and workflows behave. Scripting errors introduced through configuration can interrupt later processes and break base system functionality.
The Variable Processor runs first, so its use has the greatest effect on performance when heavy user load is expected. The steps below are numbered in the order SmartSimple completes them.
Open a Level 1, 2, or 3 Record
When a Level 1, 2, or 3 record opens, SmartSimple completes these processes in order:
-
The Variable Processor runs over the entire page in a fixed order, and repeats the work for each related record and each variable syntax. This happens on the server before the page reaches the browser. Because of the processing load, careful use of the Variable Processor is recommended when heavy user load is expected.
Each step replaced the @ syntax variables first, then the matching {{ }} variables. The Variable Processor replaces variables in this order:
-
@system.@variables. -
@me.@variables. -
@rootcompany.@variables. -
@ReportProperty()@variables. - Prefixed variables, such as
@client.@,@owner.@, and@branch.@. -
@standardfields@and@customfields@variables. -
@parent.@variables, on Level 2 and Level 3 records. -
@xml.customfield@variables. -
[#(?object=)#]list view queries. -
@ReportProperty1()@variables. -
@system2.@variables. -
<!--sslogic()-->and<!--@sscalculation()-->calculations. -
@ReportProperty2()@variables. -
<ssEncrypt>,<ssEscape>, and<ssTranslate>tags. -
@SmartFields@variables.
-
- The
SystemCall onload()script function runs on the server before the page reaches the browser. - SmartSimple sends the page to the end user's browser.
- The
_showhideheader()script call runs. It initiates which title bars show or hide. - The
onloadfunc()script runs after all page elements finish loading. Dynamic control fields are initiated afteronloadfunc()runs.
Save a Level 1, 2, or 3 Record
When a Level 1, 2, or 3 record is saved, SmartSimple completes these processes in order:
- The
savefunc()script runs when a user saves a draft, saves, or submits. Ifsavefunc()returns false, the save is canceled. - The
sbfunc()script runs after required field validation when a user saves or submits. Ifsbfunc()returns false, the save is canceled.
After a Level 1, 2, or 3 Record Is Saved
After all fields on a Level 1, 2, or 3 record are saved and updated, these processes run unseen in the background:
- The
SystemCall onsave()script function runs on the server after the custom field values are saved. - Workflow based on status are triggered if the status has changed.
?object=activity query. When a Level 3 record is saved, the Level 3 type formula runs only if it references a Level 3 variable.