When you press the Test Syntax or OK button in the Calculation Editor some checks are performed to check your calculation is valid. This does not guarantee the calculation will work, however it checks your Dependencies are correct and that specifically the syntax of the calculation is good.
The first check is against the dependencies listed in the panel on the right of the editor. A dependency is an attribute that the calculation relies on. It is only relevant for Before Save and Windows Calculation types and it is only when one of the dependency attributes is set or updated that the calculation will trigger. In simple calculations the list is set automatically as you create the calculation but you can also override this and enter your own dependencies manually.
"Invalid dependency: ....."
This means that the dependency specified could not be found. Check spelling and case.
"You need at least one dependency for this type of calculation."
(From Service Desk 7.6 onwards) This error will occur on a Before Save or Window Calculation type when there are no dependencies. This check is performed because without any dependencies the calculation would never be triggered.
The other check performed is a syntax check against the calculation itself. This check is performed by the Boo compiler which is the programming language calculations are written in.
Understanding the error messages
Syntax errors appear like this and can sometimes look quite daunting to read:
- Each line is a different error, but you only need to pay attention to the first line as the others are likely just a symptom of the first.
- The numbers in brackets refer to the line and character number of the error. For instance in the screenshot above the first error is on line 4 at character 38.
- The code that begins BCE00... is the Boo error code. Don't worry too much about that as there are only 2 or 3 different codes you will see.
- The rest of the line is the important bit telling you what the problem is.
The most common reasons for a syntax error are:
- Indenting. For more information see this document: Calculation Writing Tutorial - 3. The importance of Indenting and checking NULL values.
- Case. Everything in calculations is case sensitive so incident is not the same as Incident and tostring() is not the same as ToString().
- Colon after an "if" statement. All "if" statements must end with a colon. For more information see this document: Calculation Writing Tutorial - 2. Variables and Conditional Logic ("if" statements).
"Unexpected token: ..." and "expecting '...', found '....'
These errors are normally caused by incorrect indenting, or forgetting to end an "if" statement with a colon. For more information on indenting see this document: Calculation Writing Tutorial - 3. The importance of Indenting and checking NULL values.
" '...' is not a member of '...' "
This means you are trying to use a Method or Property that is either not valid for the type of data you're using it on or is mis-spelt. Sometimes you will get a hint for common typos: "tostring is not a member of '...'. DId you mean 'ToString' ?".