Overview
This article details the various TrackVia-specific Functions that can be used in App Scripts. It also details how you can create your own function. Click on the a Function listed below to jump to that section and see more information about its use and syntax examples:


TrackVia Functions
find()
- Allows you to look up multiple records. Use
find()
instead ofloadRecord()
if more than one record may meet your search criteria. - Returns a List of Maps (records) that match the search specified search criteria
-
find("Table Name", [:])
will retrieve all records on the specified Table.
👀 Note: find()
CANNOT search for null values
Example Syntax:
Standard:find("Table Name", "Field Name", "Field Value")
If there are multiple Tables in your account with the same Table Name, you can make your search more specific by adding the "App Name" to the search criteria:
find("Table Name", "Field Name", "Field Value", "App Name")
loadRecord()
- Allows you to look up a single existing record by matching the Field Name and Field Value, or a collection of matching Field Names and Field Values.
👀 Note: loadRecord()
will result in the error Did not return a unique result: x
if multiple records are found that match the search criteria.
Example Syntax:
Standard: loadRecord("Table Name", "Field Name", "Field Value")
If there are multiple Tables in your account with the same Table Name, you can make your search more specific by adding the "App Name" to the search criteria:
loadRecord("Table Name", "Field Name", "Field Value", "App Name")
save()
- This function can be used to add a new record to any table in the account.
- It takes 3 inputs: the name of the Table the record is being added to, the data (field names and values in the fields) for the new record, and the name of the App where the Table is located.
👀 Note: the input for the Record Data within this function MUST be a Map
of the fields from the target Table and the values you want placed in those fields. With this in mind, first create a Map
of the record you want to add to the Table, then input the name of the Map as the "Record" in the save()
function.
Example Function Syntax:
Map newRecord = [(fieldName1): "Field Value", (fieldName2): "Field Value"]) as Map
save("Table Name", newRecord, "App Name")
delete()
- Used to delete an existing record
👀Note: if you delete the record currently in view, the UI throws an error message, but the record is still deleted.
Example Syntax:
Map employee = loadRecord("Contacts","Name","Scott Carpenter") as Map
delete(employee)
addChild()
- This function is ONLY used to add Child Records to a specific Child Table of the record that triggered the app script to run
- Record data MUST be in the form of a Map
❗REMINDER: Use the Relationship link between Tables, NOT the Relationship Field when using this function. Refer to the Script Writing - Using Constants article for a detailed explanation.
Example Syntax:
addChild("Child Table Name", "Relationship ID Name", Record)
getChildren()
- Returns Child Records linked to the current record
❗REMINDER: Use the Relationship link between Tables, NOT the Relationship Field when using this function (see addChild()
above).
Example Syntax:
getChildren("Table Name", Relationship ID Name")
Custom Functions
In addition to the standard TrackVia Functions, you can create your own custom Functions to run operations in App Scripts!
Basic Syntax for Creating a Custom Function
The example below shows the basic syntax for a custom Function:
def functionName(parameters) {
// your logic
return result
}
The example below shows a custom function called "addOne" that takes an Integer as an input, adds 1 to it, then returns that result:
def addOne(int input) {
return input + 1
}
int myNumber = 0
myNumber = addOne(myNumber)
Related Articles:
Comments
0 comments
Please sign in to leave a comment.