Skip to content

Pre-execution scripts ​

A pre-execution script changes a component's configuration just before the component handles a record. Use it when a setting depends on the data: a file name built from the record, a URL chosen per customer, a query limit from the metadata.

For a value built from text, a binding expression is shorter. Use a pre-execution script when you need logic.

Add one ​

Select the component. In its properties, the Config scripts row has a C#, a Python and a JavaScript icon. Click one to open its editor. Clear pre execution scripts removes them all.

The scripts run for every record, before the component's own work, in the order C#, Python, JavaScript.

C# ​

csharp
public void Configure(IMetaData metaDataInstance, IViaType pluginConfig, IViaType inputData)
{
    var config = pluginConfig.Cast<FileWriterConfig>();
    var metaData = (viauser.FlowMetaData)metaDataInstance;
    var order = inputData.Cast<Order>();
    config.FileName = $"order-{order.Id}.json";
}

config is the component's configuration with the same field names as in the properties. Whatever you set applies to this record. The Services property gives you the flow services.

Python and JavaScript ​

The template gives you the metadata and the configuration as objects:

python
def configure(metaDataId: int, configId: int, inputDataId: int):
    metaData = FlowMetaData(metaDataId)
    config = FileWriterConfig(configId)
    config.FileName = "orders.json"
javascript
function configure(metaDataId, configId, inputDataId) {
    var metaData = new FlowMetaData(metaDataId);
    var config = new FileWriterConfig(configId);
    config.FileName = "orders.json";
}

Viaducta documentation