What is a function?
A function is a pre-built instruction that performs an operation and returns a value. The following syntax is used with functions:
Or, the first parameter can also be specified as follows:
Function names are written in lowerCamelCase, that is, the first word is written in lower case and subsequent words have the first letter capitalized (for example,
Double quotes or single quotes?
- Use single quotes to refer to field names.
If the field name that you are referencing contains any spaces, or starts with a number, the field name must be written inside single quotes.
• fieldName # Does not need to be enclosed within single quotes because the field name does not contain any spaces and starts with a letter.• 'field Name' # Must be enclosed within single quotes because the field name contains a space.• '1fieldName' # Must be enclosed within single quotes because the field name starts with a number.
- Use double quotes to indicate literal text (not a field).
emit *where type == "Direct Debit"
How do I define a variable?
A variable is a container that holds information.
Variables are defined by stating a name and what information they should contain. Variable names are specified in the following format, where the variable name is written on the left and the expression that identifies the information that it contains is written on the right:
<variable name> = <expression>
After a variable has been defined, it can then be referenced in an emit statement. Variables are useful when you are dealing with numerous edits as they can help to keep the coding cleaner and easier to read.
1. Variable "orderMore" is defined. This statement must be placed before the emit statement:
orderMore = if UnitsInStock + UnitsOnOrder < Desired then "Yes" else "No"
2. Variable is referenced in an emit statement:
emit *, orderMore
In this example, "orderMore" will be included as a new column in the output.