Lists, Lead Scoring & Workflows

DGanasan
Contributor

Custom code

Hi HubSpot, 

 

I am trying to create a workflow to update Email Sent Day based on 'Sent Date' metric available. I have created a custom field property (Email Sent Day) & a custom code to extract Day email was sent & update value (Email Sent Day). However, when i run the workflow, the custom field doesnt show any value. Can you help me check if my custom code or workflow needs any tweak?

 

DGanasan_0-1699153624444.pngDGanasan_1-1699153638496.png

DGanasan_2-1699153719145.png

 

exports.main = async (event, callback) => {
// Extract the 'sent' date string from the inputFields
const hs_email_last_send_date = event.inputFields['hs_email_last_send_date'];

// Replace '/' with '-' to create a format "dd-mm-yyyy" for Date parsing
const dateParts = hs_email_last_send_date.replace(/\//g, '-');

// Define an array of day names
const dayNames = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];

// Get the day of the week as a number (0 for Sunday, 1 for Monday, etc.)
const dayOfWeek = new Date(dateParts).getDay();

// Get the day name from the array based on the day of the week
const dayName = dayNames[dayOfWeek];

// Define the 'email_sent_day' property in the code
const email_sent_day = dayName;

console.log(email_sent_day);

/*****
Use the callback function to output data that can be used in later actions in your workflow.
*****/
callback({
outputFields: {
email_sent_day: email_sent_day
}
});
}

0 Upvotes
1 Reply 1
MiaSrebrnjak
Community Manager
Community Manager

Custom code

Hi @DGanasan,

 

Thank you for reaching out to the Community!

 I wanted to invite a couple of subject matter experts to this thread to see if they can help review the custom code action in your workflow:  

Hi @HFisher7@Teun@DanielJeal, do you have any advice for @DGanasan? Thank you! 

 

Cheers
Mia, Community Team 


Wusstest du, dass es auch eine DACH-Community gibt?
Nimm an regionalen Unterhaltungen teil, indem du deine Spracheinstellungen änderst


Did you know that the Community is available in other languages?
Join regional conversations by
changing your language settings

0 Upvotes