I’m using hubspot CRM to send data daily to my spreadsheet:
In column A it fills with a GCLID
In Column B it fills with nothing
In Column C it fills if a UNIX date value
In Column D it fills with nothing
In Column E it fills with nothing.
So i built a Appscript to edit these fields like:
In Column A nothing Happens
In Column B it fills with a text
In Column C it converts the unix date value to regular date format with epochtodate
In Column D it fills with a numeric value
In column E it fills with a text
I can’t say more than this because it’s some private data.
The appscript works just fine, when i edit something, like i add data on the row below, it edits and fills perfectly.
But when hubspot does via API nothing happens.
I’d like to make this appscript works when hubspot sends data to the spreadsheet too.
Here’s the script i’m using.
function onEdit(e) {
var sheet = e.source.getActiveSheet();
var range = e.range;
var startRow = range.getRow();
var endRow = startRow + range.getNumRows() - 1;
for (var row = startRow; row <= endRow; row++) {
// Coluna B
sheet.getRange(row, 2).setValue('Definitivo - GADS - Conversões Offline - Match all');
// Coluna C (Converter valor Unix para data usando a fórmula EPOCHTODATE)
var cell = sheet.getRange(row, 3);
var cellValue = cell.getValue();
if (!isNaN(cellValue) && cell.getFormula() === '') {
// Adicionar a fórmula temporariamente
cell.setFormula('=EPOCHTODATE(' + cellValue + ', 2)');
// Aguardar um momento para a fórmula calcular o valor
Utilities.sleep(500);
// Converter o valor calculado para um valor estático
var calculatedValue = cell.getValue();
cell.setValue(calculatedValue);
}
// Coluna D
sheet.getRange(row, 4).setValue(2100);
// Coluna E
sheet.getRange(row, 5).setValue('BRL');
}
}
Already tried using on change and on edit triggers.
Already tried using time as a trigger but it changes all rows, i need it to trigger only on new filled rows, like new data sent from hubspot.