Conditional Keychain Example
The following example demonstrates an if-statement using a Dynamic Data Key. This allows us to highlight different values or ranges contextually, making important values stand out.
Assuming a key named "myValue" has been created, and contains a numerical value, we can use the following syntax:
In the image below, the Fill property is also using a dynamic data key, so the Fill Color will be disabled if myValue is less than 1, Blue if myValue is between 1 and 4, and Green if greater or equal to 5. Note that in the Property inspector, the @ symbols are not needed.
To add more color-value pairs, we simply add more if statements to the end of the expression with a colon:
Operators and Functions
The following operators may be used in a Keychain expression.
|Parenthesis||(expr) Nested expressions||Any portion of a Key Chain can be enclosed with parenthesis to guarantee precedence.|
|Multiplicative||*, /, % Multiply, divide, modulo|
These are the most common and intuitive operators. You might want to display @quantity*price@ in an invoice line-item or calculate a percent like this @profit/revenue*100@.
|Additive||+, - Add, subtract||See multiplicative above|
|Relational||>, <, >=, <= Greater-than, less-than, greater/less-than-equal||These are most useful for conditionals: @amount>=0? "Credit" : "Debit"@ or @name=="this"? "that" : name@|
|Equality||==, != Equal, not-equal||See Relational above|
|Logical||AND &&||These operators make it possible to test multiple conditions: @revenue>100 && budget<50? "Winner!"@ or @name=="Jack" || name=="Sam"? "Good Name!"@.|
|Logical||OR ||||See and above|
? : If/then - with form
"expr? true_expr : false_expr"
Provides IF/THEN/ELSE expressions. Note: a false expression is optional. 'null' will be evaluated to false and non-null as true. You can provide null substitutions like this: @name? name : "(None provided)"@. You can also nest conditionals for more conditions.
|Assignments||=, +=||For the brave, you can create temporary variables for use in a report. Most of the functionality you might use this for is covered in more intuitive ways (such as the Running key), but it is possible to define a variable in a header row: @revTotal=0@ and update it in details rows @revTotal+=revenue@.|
The following functions return floats.
|floor(float)||Round input down to the nearest whole number.|
Round input up to the nearest whole number.
|round(float)||Round input to the nearest whole number.|
|abs(float)||Returns the absolute value of the input (if number < 0 return number * -1).|
|min(float, float)||Returns the input number with the least value.|
|max(float, float)||Returns the input number with the greatest value.|
|pow(float, float)||Returns first number to the second number power.|
The following functions return strings.
|startsWith(String, String)||Returns true if the first string starts with the second.|
|endsWith(String, String)||Returns true if the first string ends with the second.|
|substring(String, int start)||Returns a substring of String beginning at position start.|
|join(List aList, String aKeyChain, String aDelimeter)||Used to display an individual attribute of individual objects as a single String. Suppose you have a list of movies and want to show their titles in a comma separated list: @join(getMovies, "getTitle", ", ")@|
|substring(Object aString, int start, int end)||Obtain a subset of a given string. This could be useful if you wanted to restrict a text field to a certain number of chars:@substring(title, 0, 10)@|