In our workflows, we want to be able to replace the value of a date property with the output of a custom code action when using the “edit record” option.![]()
We created code in Data Hub that adds a month to a given date and sets it to “the 1st of the month.” When we get an error, it tells us to add a piece of code that prints the value to the property, which is a problem because we can’t connect to the API without an external integration and developer work.
The other option we were given is “edit record,” but we found that there’s no option to use this code! The moral of the story is, we’re stuck halfway.
It would be great if you could add this option, both for dates and for printing values in existing properties.
**
**
Thank you very much.
Code we added:
// 1. ID del negocio desde el contexto del evento
const dealId = event.object && event.object.objectId;
// 2. Fecha de cierre desde el input de la acción
const closeDateStr = event.inputFields.deal_close_date; // clave definida en la acción
if (!dealId) {
console.log(‘No se pudo obtener el ID del negocio desde event.object.objectId’);
return callback(null, {});
}
if (!closeDateStr) {
console.log(‘No hay fecha de cierre, no se actualizará fecha_de_ultima_renovacion’);
return callback(null, {});
}
const closeDate = new Date(Number(closeDateStr));
if (isNaN(closeDate.getTime())) {
console.log(‘Fecha de cierre inválida:’, closeDateStr);
return callback(null, {});
}
// 3. Calcular el primer día del mes siguiente (UTC)
let year = closeDate.getUTCFullYear();
let month = closeDate.getUTCMonth(); // 0 = enero, 11 = diciembre
if (month === 11) {
year += 1;
month = 0;
} else {
month += 1;
}
const nextMonthFirstDay = new Date(Date.UTC(year, month, 1, 0, 0, 0, 0));
const nextMonthFirstDayTimestamp = nextMonthFirstDay.getTime();
console.log(
‘Negocio:’,
dealId,
‘Fecha cierre:’,
closeDate.toISOString(),
‘-> fecha_de_ultima_renovacion:’,
nextMonthFirstDay.toISOString()
);
// 4. Inicializar cliente de HubSpot
const hsClient = new hubspot.Client({});
// 5. Actualizar la propiedad en el negocio
await hsClient.crm.deals.basicApi.update(dealId, {
properties: {
fecha_de_ultima_renovacion: nextMonthFirstDayTimestamp,
},
});
console.log(
`Negocio ${dealId} actualizado con fecha_de_ultima_renovacion = ${nextMonthFirstDayTimestamp}`
);
// 6. Devolver la salida opcionalmente
return callback(null, {
fecha_de_ultima_renovacion: nextMonthFirstDayTimestamp,
});
} catch (error) {
console.error(‘Error en custom code de fecha_de_ultima_renovacion:’, error);
return callback(error);
}
};
