Apply transformer for each row in table - adding new column

Hi,
How to aplly transformer for each column in table.
For instance:
Coulmn A = 10.
New column B = Column A + 5

I know that I can do it directly from mapper saying {{currentRow + 5}}.

But I have more complicated math and would like to do it within transformer and call transformer in mapper like {{transformer1.value}}

But how can I call ""currentRow" within transformer itself?

Regards,

Hi Here is an example where I am using a transformer to add a formatted preview to each object in a collection.

// format message for preview
let nl = "\n";
let sp = " - ";

data.forEach(r => {

  var days =  [r.d1, r.d2, r.d3, r.d4, r.d5, r.d6, r.d7];
  for (let day of days) {
    let overview = "";
    if (day) {
      if (day.status) overview += day.status; 
      if (day.status_info) overview += sp + day.status_info; 

      if (day.message) {
        for (let m of day.message) {
          overview += nl + "id" + sp + m.id + nl
                + "sequence" + sp + m.sequence   + nl
                + "text" + sp + m.text   + nl
                + "link" + sp + m.link   + nl
                + "image_url" + sp + m.image_url; 
        }
      }

    } else {
      day = {};
    }
    day.overview = overview;


  }
  return r;
})

return data;
2 Likes

Hey! I've created a simple example, but it should work for more complicated math. You just need to return an Array from the JS Transformer and then we can access each specific row's information with {{ transformer1.value[i] }}.





Here we are simply adding 100 to the id of every row in the table. But more complicated manipulation of the data should work in the exact same way!

3 Likes

Hi folks,

This post needs a bit of an updated solution. In Joe's previous solution before, he is using a 'Table Transformer' which belongs to the v1 table which is now depreciated.

You currently cannot set the returned data from a JS query or a Transformer to be the 'Source' of a custom column added to a table. Also the 'Calculation' input field is not a feature of the v2 table.

Instead, you can either save the table's data to a variable, and then manipulate that array or objects with Javascript to add in another column with a value that is the result of any operations or modifications you want to make.

Or you can do any logic transformations from the 'Value' input field of a newly created column that has been manually added.