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 status of the review session. The status is in the workflow variables.
To retrieve it and use it in my script as a variable call 'decision', we invoke the variable using 'context'.
def decision = context.getWorkflowStringVariable('status')
3 Metadata instance
Secondly, we will need to invoke the metadata instance of the asset being reviewed. We are going to invoke it as a variable called ‘assetMeta’ which I can then use in my script later.
3.a invoke asset service
I first declare my variable and then I call the assetService to get my metadata
def assetMeta = flexSdkClient.assetService.getAssetMetadata()
3.b invoke Asset ID in context
From a script I can invoke the metadata of all assets that are present in Flex. 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 as Long
final result :
def assetMeta = flexSdkClient.assetService.getAssetMetadata(context.getAsset().id as Long)
3.c (optional)
Note that this field can be filled with a fixed value ( asset ID ) e.g. if the goal is to modify the same asset every time
def assetMeta = flexSdkClient.assetService.getAssetMetadata(3843284)
4 IF and ELSE
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.
4.a IF Decision
Let's start with IF and declare what on which condition we will run the following block of code when the decision is Approved.
if( decision == 'Approved'){
Now that this is done in my IF code block, I will be able to specify what I want to execute if the decision is 'approved'.
4.b Modify metadata field
To modify a metadata field in my instance, we just need to call
- Invoke the metadata instance we created earlier. (assetMeta)
- Choose the field in this instance. (acalder-review)
- Define the value we want to apply to this instance. (approved)
4.c Save metadata modification
Now we want to save our changes using set asset value. To do this we will need to invoke a new service. Specify the asset id on which we want to save and the changes we want to save.
4.d return Decision
And finally we will return our decision withe the name of the transition we wish to make in the workflow. The code it’s pretty simple write :
return 'approved'
Attention the name you return here must be the same as the one entered in the transition of your workflow.
4.e Else Block code
For Else there is no need to define a value to match; it will run by default if ‘if’ is not triggered. Now I just need to copy/paste the same code as the previous one, and change the approved values by refused
And finally we end our script action by adding a closure
}
Comments
0 comments
Article is closed for comments.