Task options

Task options are configuration values for the task that can tweak the task logic without changing code. For example, if you have a task for exporting product data to CSV files, and you don't care about the metrics for all the products in your store. You can have a task option defining how many top products to export to csv. This option can be changed more intuitively on the UI.

How to add task option

on the left panel, click on Add new option.

You will see a pop-up for creating a task option. You can define one of the 6 option types:

  • Text input

  • Number input

  • Boolean switch

  • Array input

  • Key/Value input

And you can configure the key and description. Key is important here as it will be the key in the option object for the task handler function. A key can only contain alphanumeric characters and underscore.

After setting up the task, you can see a form show up on the side where you can provide the task option values.

Now in the code, you can reference object values like this:

const { auths, libs } = require('platform');
​
module.exports = async (event, options) => {
console.log(options.special_tag_prefix);
console.log(options.give_me_top_n_products);
};

Benefit of task options

  1. Allow tweaking the task behavior without touching code. This could be useful for non-technical members of the team.

  2. The task can be exported as template which can be re-used under different situations using different configuration value. This makes a task very flexible and powerful.

  3. Tweaking configuration with different app environments. For example, the behavior of the task in staging/production may be different.