Set condition in job output mask

Hello,

Is there a possibility to set a condition in job output mask in output creation?
I would like to check the type of the document based on field from metadata document tags and use different metadata document tags to name the file depending on document type.

You can, actually.

Consider the following output mask:

${if(document.metadata.Country == 'CA'){'Canada';}else{'United_States';}}.${template}

Using this with an appropriate job preset and separation results in files being named as you see them below:

Capture

My data only contains either “CA” or “US” for the Country code that I’m feeding into metadata, but I can leverage that to build a condition to do whatever I want in the output mask. You just build your condition following standard Javascript syntax inside of the ${} wrapper as you see below. Then just remove the extra line breaks to make it fit nicely in the box.

${
    if (document.metadata.Country == 'CA') {
        'Canada';
    } else {
        'United_States';
    }
}

Here I’m using fixed values as my output values from the IF statement, but I could just as easily use metadata values there as well like this, where ABC and XYZ represent different fields in your data:

${
    if (document.metadata.Country == 'CA') {
        document.metadata.ABC;
    } else {
        document.metadata.XYZ;
    }
}

That said, however, you’ve got very limited space to write this statement and it becomes exceptionally hard to read (and therefore to debug/alter) the more complex it gets.

The better place to do this sort of conditional logic would be back in the datamapper. Create a javascript based extraction that can set a single “documentName” field to a given value based on the values in other fields. Then you pass that field over to your output preset and use it as is.

Capture2

3

1 Like

Thank you very much! Very helpful and complete answer :slight_smile: