Overview
Refer to this guide to help you identify, interpret, and resolve App Script errors quickly and efficiently.
Click the links below to jump to that section for more information:
- Common Scripting Mistakes and How to Avoid Them
- Compilation Errors
- Runtime Errors
- How to Read and Interpret Error Logs
- Using Loggers to Test Scripts
-
App Script Timeouts and How to Avoid Them
Common Scripting Mistakes and How to Avoid Them
Common Scripting Mistake | 🛠️ Resolution |
Referencing a field name that has changed, and now the script no longer works. | Use System IDs as Constants for fields and relationships (see the Script Writing - Using Constants article for more details). |
Comparing date or number values without explicitly casting. | When defining a Variable, be sure to append as Date , as Double , etc. to explicitly cast the Variable type to match it with the field's value type. |
Forgetting to check for null values in a referenced field |
Always check for null before using a field (see the Runtime Errors section below). |
Logic running unexpectedly | Use loggers to test conditional logic paths (see the Using Loggers to Test Scripts section below). |
Using the wrong bind variable (currentValues /previousValues ) for the App Script Event Type. |
Understand how the App Script's Trigger Event Type behaves in the App Script Order of Operations (see the Intro to App Scripts article for more details) |
Compilation Errors
Compilation errors occur when the script fails to compile before it runs (e.g. it throws an error when you try to save changes to your script). Usually, this is due to syntax mistakes in your code, such as:
-
Typos such as incorrect spelling of a Variable name or Type.
The example below shows the error message thrown when a Variable name is misspelled asduDate
instead ofdueDate
:
🛠️ RESOLUTION: correct the spelling of the Variable name so that it is an exact match to the Variable name as it was defined (changeduDate
todueDate
). We recommend that you Copy + Paste the defined Variable name when referencing it elsewhere in the script to avoid issues like this.
The example below shows the error message thrown when a Variable Type is misspelled asBoolan
instead ofBoolean
:
🛠️ RESOLUTION: correct the spelling ofas Boolan
toas Boolean
.
-
Missing brackets, quotes, or parentheses.
The example below shows the error thrown due to a missing closing quote:
🛠️ RESOLUTION: Add the missing closing quote"
for"Awaiting Approval"
.
-
Using an incorrect Variable type for the value type.
The example below shows the error thrown when attempting to define a number value as aDate
Variable:
🛠️ RESOLUTION: The Variable you are defining astotal
is the sum of two number values, so if you definetotal
as aDouble
instead of aDate
Variable type.
-
Invalid method calls or incorrect use of operators.
The example below shows the error thrown when attempting to use the.contains()
method with aDouble
Variable type:
🛠️ RESOLUTION:.contains()
is a List method and you are trying to apply it to aDouble
Variable type. Be sure to use a method that is suited to the values of the Variable type. In this case, instead of using.contains()
, use a method that can be applied to number values, such as.round()
, or you can convert theDouble
to aString
of text by using.toString()
.
Runtime Errors
Runtime errors occur after the script starts running, usually during execution.
Some Common Causes of Runtime errors are:
-
null
values where values are expected.
To avoid Runtime errors, be sure to check that a field is notnull
before referencing it in the script. See the example below for how to check fornull
in a script:if(currentValues["Due Date"] != null){
}
- Field references that don't exist (e.g. incorrect field name, or referencing a field that has been deleted from the Table.) In the example below, the field's name was originally "Needs Approval Check", but the field's name was changed to "Needs Approval", but the script still references the old name:
if(currentValues["Status"] = "Awaiting Approval"){
currentValues["Needs Approval Check"] = "Awaiting Approval"
}
And this is the resulting error when trying to update the record:
How to Read and Interpret Error Logs
While in the App Script Editor, at the top-center of the page you can toggle between the Script Editor and the Error Log:
By toggling to the Error Log, you will be able to view error messages related to this App Script as well as any Logger message (e.g. logger.info()
) outputs for Loggers in this script.
The Error Log displays logged information in four columns:
1. Log Level - Displays whether the log is an Error message or an Info message (e.g. the output from logger.info()
)
2. Script Name - Displays the name of the App Script the message is related to (e.g. the App Script you had open in the Script Editor before toggling to the Error Log).
3. Error - Displays the information contained in the Error or Logger message.
4. Date/Time Logged - Displays the timestamp of when the message was logged.
How to Interpret Error Messages
Refer to the example error message in the screenshot below:
-
Details shown in the Red Box - From left to right, this shows:
- the Table name (Projects),
- the Table ID (177),
- the App Script Event Type (BEFORE_UPDATE),
- the App Script ID (13),
- the line of the script where the issue was found (16), and
- what kind of issue it is (Unexpected Input - e.g. a script syntax issue)
-
Details underlined by the Green Line - the line of the script where the issue was found.
👀 NOTE: the Error log is not always precise in identifying the exact line where the issue exists, and the identified line may be off by one line. Typically, the line identified in the message is one line after where the issue actually exists.
In this example the message says the issue is on line 16 when the piece of the script the message points to as the issue (see the Blue Arrow) actually exists on line 15.
-
Details in the Blue Box - This shows the number of issues that were found. In this example, one syntax issue was found, but if there were more syntax issues, this might says "2 errors" or "3 errors", etc.
-
The Blue Arrow points to the carrot ^ which indicates the exact portion of the script where the error can be found.
In this example, the carrot ^ is pointing to the field name that is being referenced. In the error message, you can see that the field name has quotes before the name, but is missing the closing quotes at the end of the name["projectTitle]
. This is the syntax issue that is causing the Compilation error.
Using Loggers to Test Scripts
It is common to use Loggers while writing scripts to test the logic in your scripts and ensure that it is behaving the way you expect.
Refer to the Script Writing - Using Loggers article for a detailed breakdown of what Loggers are, and examples of how to use them to test your scripts.
App Script Timeouts and How to Avoid Them
App Scripts must complete their actions within a set execution time. The default time limit is 2 seconds.
The number of actions the script is taking and the number of records that it is performing those actions on contribute to how much time it takes for the actions to be processed completely. As more and more records are added to a Table over time, the time it takes for the script to perform its actions on all of the records will take more and more time to complete.
If the script cannot complete successfully within this timeframe, the script will timeout and result in an error.
Common Causes
- Large loops (e.g. a loop that is iterating through thousands of records)
- Infinite loops or deeply nested logic conditions
- Chaining Scripts (e.g. the actions performed by one script trigger another script to run, and so on)
- A large number of logger messages included throughout the script
How to Avoid Timeout Issues
- Write your scripts efficiently. Refer to the App Script Best Practices article for more information and examples.
- Instead of using a bunch of nested logic conditions in your script, consider using Flows to navigate that process instead of App Scripts.
- Be aware of how actions in one script may trigger other scripts to run. If you think the timeout may be caused by chaining App Scripts, identify the possible scripts involved and troubleshoot by disabling one script at a time and try re-triggering the script to see if it is able to complete successfully. Repeat this process of disabling scripts in the chain until the script is successful to identify which script in the chain is the likely cause of the timeout.
Related Articles:
Comments
0 comments
Please sign in to leave a comment.