ActionScript Basics
In Hexabase, operations on database items are called actions. Javascript code can be assigned to these actions. This is ActionScript.
In ActionScript, you execute assigned code by calling an action.
※ If you call the Update Item API in the ActionScript of the "update contents" action, the "update contents" action will be called recursively.
How to assign ActionScript
- Display any item details in the database
- In the item's action menu, click the edit button for the action for which you want to set ActionScript (e.g., update content)
- Add Action Script > Edit Action Script
ActionScript editor
ActionScript can be edited with the Action Script Editor.
Information about the applicable item can be received as an argument by implementing the main function in JavaScript. Information that can be referenced as an argument can be viewed on the left side of the action script editor.
Hello world
- Select "blank" in "Example Script" > The code for the main function is created.
- Writing code for the logger object > You can display data in the log window.
function main(data) {
logger.info("Hello!!");
}
- Display the log window with the "Log" button
- Run the script with the "Try" button
Information available in ActionScript
The argument data passed to Main() in the left pane of the action script editor.
Argument datamainly contains the following information:
- Login user information
- Item ID information
- Datastore information
- Status
- Field
- Available actions
- Item information
- the Value of the field
- Item related data information
- ID information of related Item
- Related database
- ID of the related Item
- ID information of related Item
※ ActionScript does not have a retry or rollback mechanism in case of failure, so it is better to consider whether to periodically check for inconsistent data or implement a retry program in case of failure.
Prescript and postscript
There are two types of ActionScript:
- Prescript: Executes before processing when the action is called
- Postscript: run after processing when the action is called
Call Hexabase API
In ActionScript, you can use the Hexabase API with the callAPIAsync function or callAPI function.
callAPIAsync(
Method, // HTTP Method “GET”,”POST”など
URL, // APIのURL
Params, // APIへ渡すパラメータ
Callback // 実行結果を取得するコールバック関数
)
Specific implementation examples
Error handling
You can enable "Pre-Script: on Error, stop action execution" to stop the script when an error occurs.
function main(data) {
logger.info("Hello!!");
throw new Error("message from 'throw new Error()'");
}
Fixed Token settings
If you need to use a fixed token in your program to call an external service, register the constant to be passed to ActionScript in the Hexabase application settings.
To use this feature, enable Developer Features in the the user profile settings in advance
Constant registration procedure
Once the constants are registered, {SLACK_TOKEN_1} will be replaced with "XXXXXXXXXXXX" when ActionScript is executed.
- Open "Application Settings"
- Select the "Program Extensions" tab
- Register constants
- Constant name:SLACK_TOKEN_1
- Value:XXXXXXXXXXXX
Sample code
ActionScript sample code can be called up in the right pane of the ActionScript editor.
The following sample code is currently available:
- blank
- slack
- simpleAsync
- sendGridExample
- sampleCallAPI
The sample implementation is also explained on the next page.