Create a changeset column for a table

Hello,

I was looking to create a changeset column which records the names of the edited columns (not values) i.e., Status and Status Reason for each row in table 1. This column will later be used the specify which CRM fields need to be updated downstream. Here is my JS so far, which does not successfully record the changeset.

const tableData = formatDataAsArray({{ table1.data }})

return tableData.map(row => {
  const changeset = row.changeSet || {}
  const changesetString = JSON.stringify(changeset)
  return {
    ...row,
    changeset: changesetString
  }
})

Best regards,

image

Still running into this issue. @SigmaverseDev

Try removing
formatDataAsArray()

Then, I get ""tableData.map is not a function""

const tableData = formatDataAsArray( table1.data )
Remove the curly braces too:
The following worked for me:

const tableData = table1.data ;

return tableData.map(row => {
  const changeset = row.changeSet || {}
  const changesetString = JSON.stringify(changeset)
  return {
    ...row,
    changeset: changesetString
  }
})
1 Like

Hi @ttam_ei

If this code is in a Javascript query, you'll want to remove double curlies {{}}.

If you were using a Javascript transformer, then you would want to still use the double curlies.

However, the changeSet will be a different property than .data.

This post might be helpful for your use case

You could try something like this:

const tableData = formatDataAsArray( table1.data )
  
return tableData.map((row, index) => { 
  const changeset = table1.changeSet[index] || {};
  const changesetString = JSON.stringify(changeset); 
  return { 
...row, 
changeset: changesetString 
  }
})

Works perfectly. Thank you!

1 Like