One of the most powerful aspects of the Flex platform is the ability to be able to write scripts to perform custom processing.
For example, you could make an external HTTP REST call, inserting the results as asset metadata values. Within scripts, Flex provides an SDK that allows you to manipulate configuration and objects in a standard and well-defined manner.
There are 2 ways to write scripts within Flex:
- Groovy script
- External scripts - compiled JVM-compatible code in JARs (e.g. Groovy, Java, Scala)
Groovy scripts are added to supported actions, via their configuration. Note that Flex currently supports Groovy v2.5.
The following is an example script, which could be executed in a JEF Script action, which creates a new media placeholder asset:
def execute() { def assetService = flexSdkClient.getAssetService(); NewAssetPlaceholder asset = NewAssetPlaceholder.builder() .type("media-asset") .name("demo asset 1") .build(); assetService.createAsset(asset); }
External scripts are compiled code packaged in to JARs, and hosted via a standard URL (e.g. HTTP, file). These allow customers to write re-usable and testable binaries (see External Scripts for more information).
Scriptable Actions
The following actions provide support for scripting:
Actions
Type | New Action | Legacy Action | Purpose |
Decision | JEF Script Decision | Groovy Scripted Decision Action | Controls workflow simple branch execution via the return value of a groovy script |
JEF Script Multi-Decision | Groovy Scripted Multi-Decision Action | Controls workflow complex branch execution via the return value of a groovy script | |
Message | JEF HTTP Message | Scripted HTTP Message | Sends an HTTP message, allowing the request and/or response to be processed via groovy script |
Script | JEF Script | Groovy Script Action | Executes either internal or external scripts |
Wait | JEF Wait For Named Signal | Groovy Scripted Wait For Named Signal Action | Pauses workflow execution until a signal is received. Groovy script can be used to control whether the action should wait for the signal |
JEF Wait For Script | Groovy Scripted Wait Action | Pauses workflow execution until a groovy script returns true, or times out |
Timed Actions
New Action | Legacy Action | Purpose |
JEF HTTP Message | Timed HTTP Message | Sends an HTTP message on a schedule, allowing the response to be processed via groovy script |
JEF Script | Timed Groovy Script | Executes internal or external groovy scripts on a schedule |
The new actions execute via the flex-jobasyncexecutor-service, and as such, any scripting interactions with Flex occur via its REST APIs.
Help writing scripts
The following pages are useful guides to help accelerate the writing of Flex scripts:
- Flex Scripting: Best Scripting Advice
- Flex Scripting: Best Practices
- Flex Scripting: Locking
- Flex Scripting: Transactions Within Scripting
- Flex Scripting: Things to Avoid
- Flex Scripting: Defensive Script Writing
- Flex Scripting: Writing External Scripts
- Flex Scripting: Scripting Examples
Comments
0 comments
Please sign in to leave a comment.