Samples

Log to Job History

    def myVar = 'some_value'
    context.logInfo("This is a log statement. My variable is: $myVar")
  

Interact with Workflow Variables

 def asset = context.asset
context.setMioObjectVariable("myAsset", asset)
def assetLink = context.getMioObjectVariable("myAsset")
def myVar = 'some_value'
context.setStringVariable("myVar", myVar)
def myStringVar = context.getStringVariable("myVar")
def now = new Date()
context.setDateVariable('myDateVar', now)
def myDateVar = context.getDateVariable('myDateVar')    
    

Note that Context::getMioObjectVariable() method returns an object of type ObjectLink. If you want to exchange this for a “real” object (e.g. an asset), you can use the appropriate service to do so:

def asset = context.asset
context.setMioObjectVariable("myAsset", asset)
def assetLink = context.getMioObjectVariable("myAsset")
def assetService = services.assetService
def storedAsset = assetService.getAsset(assetLink.id)
                  

Store Asset on the Workflow Context

// Get asset from context
def asset = context.asset
// Store another asset
context.setAsset(1234)
// Remove asset from 
contextcontext.removeAsset()
      

Get Asset Metadata

def asset = context.asset
def assetService = services.assetService
def metadata = assetService.getAssetMetadata(asset)
def directorField = metadata.getField('director')
if ( directorField.hasValue() ) {
   def director = directorField.value as String
   context.logInfo("The director is: $director")
}        

Update Asset Metadata

def asset = context.asset
def assetService = services.assetService
def metadata = assetService.getAssetMetadata(asset.id)
def directorField = metadata.getField('director')
directorField.setValue('Michael Bay')
assetService.setAssetMetadata(asset.id, directorField)   
  
Note: **You must call setAssetMetadata() after updating your fields.

Set asset metadata by JSON

        def assetService = services.assetService
def asset = context.asset
def metadataStructure = [
       'myField1': 'value 1',
       'myField2': 'value 2',
       'myComplexField': [
               'subField1': 'value 1',
               'subField2': 'value 2'
          ]
]
def metadataJson = groovy.json.JsonOutput.toJson(metadataStructure)
def metadata = assetService.getAssetMetadata(asset)
metadata.fromJson(metadataJson)
assetService.setAssetMetadata(asset, metadata)

Find Asset by Metadata Value

def assetService = services.assetService
// Build query
def assetStatus = 'FINISHED'
String metadata = "status:$assetStatus"
def query = new AssetAPIQuery(
       metadataDefinitionId: 1234,
       metadata: [metadata]
)
// Run query
def finishedAssets = assetService.getAssets(query)
if (finishedAssets.totalCount > 0) {
   // Print all asset names
   finishedAssets.assets.each { asset ->
       context.logInfo("Found finished asset: $asset.name")
   }
}
   
https://help.ooyala.com/sites/all/libraries/dita/en/media-logistics/flex/dev/53/technical_start_guide_samples.html

Was this article helpful?