This article has been written to help users participating to the Dalet Flex Challenge 2023 - Challenge number 2 Review. The configurations described here are not intended to be reproduced in a production environment.
1 Beginning
As we did with Datalink first I declare that I want a script to be executed by typing 'def execute' .
def execute(){ |
2 Get decision result
In order to make our decision, we need to fetch the information of the media assset in the context of the workflow.
I first declare my variable 'asset' and then I call the assetService to get my asset information.
def asset = flexSdkClient.assetService.getAsset() |
From a script I can invoke the information of all the assets that are present in Flex database. But in our case we want a specific asset that is in the context of the workflow. So I complete my call by filling :
context.getAsset().id |
final result ( Variable = Asset info via assetService for Asset in context )
def asset = flexSdkClient.assetService.getAsset(context.getAsset().id) |
4 IF and ELSE
The long awaited moment has arrived. It's time to do our decision and modify the metadata instance with the corresponding result. For this we will use IF.
The general working of this statement is that first a condition is evaluated in the if statement. If the condition is true it then executes the statements thereafter and stops before the else condition and exits out of the loop. If the condition is false it then executes the statements in the else statement block and then exits the loop. The following diagram shows the flow of the if statement.
Let's start with IF and declare what on which condition we will run the following block of code when the asset is Published.
With IF which condition we will run the following block of code. We want to decide the future transition in the workflow, whether the asset is published or not.
To do this I just need to call up my previously defined asset variable and use an operator == to define when I want to trigger my code contained in IF. (more information on operator here ➡️ https://groovy-lang.org/operators.html#_assignment_arithmetic_operators) In our case, we will trigger the code block when the value is equal to true.
if(variable operator value ){code block}
if(asset.published == true){} |
Finally we will return our decision with the name of the transition we wish to make in the workflow. The code it’s pretty simple write :
return 'skip' |
🚨Attention the name you return here must be the same as the one entered in the transition of your workflow.🚨
For Else there is no need to define a value to match; it will run by default if ‘if’ is not triggered.
else{ return 'publish' } |
And finally we end our script action by adding a closure
} |
Comments
0 comments
Please sign in to leave a comment.