Hi,
I am facing an issue in running a code which was provided in Hubspot Custom Code automations example. here-Data Hub Use Case Library
I am specifically trying to implement- https://github.com/HubSpot/sample-workflow-custom-code/blob/main/samples/calculate_contract_end_date.js
after a an automation-https://github.com/HubSpot/sample-workflow-custom-code/blob/main/samples/create_renewal_deal_and_associate_with_company.js takes place so we can calculate the renewal date which is one day after the contract end date. I don’t know node js at all.
Below is the code I currently have with the inputs and output defined. But when I create the output end_date and copy it to the property or the field in deals but it doesn’t work. Can anyone help regarding this?
// The following snippet applies to the Deal object, but can be modified to calculate a property on any Object
// This snippet requires 3 custom properties created in HubSpot:
// “Start Date” (date) / “End Date” (date) / “Duration” (number)
const hubspot = require(‘@hubspot/api-client’);
exports.main = (event, callback) => {
// Set up the HubSpot API client
const hubspotClient = new hubspot.Client({
accessToken: process.env.table_bi
});
// Use the client to pull information relating to the currently enrolled deal
hubspotClient.crm.deals.basicApi.getById(event.object.objectId, [“start_date”,“duration”,])
.then(results => {
// Store properties in variables
let startDate = results.body.properties.start_date;
let duration = results.body.properties.duration;
// Calculate the end date from the variables input
let d = new Date(startDate)
let i = parseInt(duration)
let end_date= new Date(d.setDate(d.getDate()+i))
end_date= end_date.getTime()
callback({
// Store the calculated date in a workflow output - don’t forget to copy that value to your “End date” property
outputFields: {
end_date: end_date
}
});
})
.catch(err => {
console.error(err);
});
}



