Erwan Kerfourn
- Updated
As we did with Datalink first I declare that I want a script to be executed by typing 'def execute' .
def execute(){
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')
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.
I first declare my variable and then I call the assetService to get my metadata
def assetMeta = flexSdkClient.assetService.getAssetMetadata()
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)
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)
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 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'.
To modify a metadata field in my instance, we just need to call
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.
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.
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.