Filtering in Celigo using Javascript

Filtering in Celigo using Javascript

Tags :

Category : Uncategorized

Filtering in Celigo flows is of two types.

  1. Output filter – Used to filter data exiting an import(lookups)/export step
  2. Input filter – Used to filter date entering an import step

To add filters on a flow step

  1. Click on define options in the import/export step
  1. Now you can see the filter symbol next to your import/export

The symbol with the arrow exiting shows the output filter and the arrow entering shows the input filter

Now you can see the page where you can add your filter conditions

This page contains 3 parts:

  1. Input – you can see the input data here
  2. Rules – where you can define your filter conditions
  3. Output – Here you can see the output result after filtering

Note: The output section only shows the value TRUE/FALSE which indicates your data after filtering will proceed to the next step or not.

Usually, filters are added using rules. To add rules, simply pick the input field to which the filter should be applied, choose the action to be performed on the data, and the operand

We can also use javascript for implementing complex filter conditions.

Steps to create a javascript filter :

  1. You can switch between Rule and Javascript from your filter page 
  1. Before that, you need to create a javascript for your filter

Go to the Scripts in the Resource section and create a new script

  1. Create a script by giving it a name and selecting the filter function.
  1. Now go back to your filter page, Switch to javascript and select the script you created
  1. You can change your script if needed.

Here is an example record:

{

“record”: {

   “orderId”: 123,

   “total”: 99.99,

   “state”: “ca”,

   “items”: [

       {

           “description”: “Hat”,

           “qty”: 3

       },

       {

           “description”: “Shoes”,

           “qty”: 1

       }

   ]

}

}

Here is the JavaScript function:

function filter(options) {

   for (var i = 0; i < options.record.items.length; i++) {

       if (options.record.items[i].description === “Hat”) {

           return false;

    }

   }

           return true;

}

Note: If the function is set to “false” the record will be ignored. If the function returns “true” the record will be processed.