APIs & Integrations

MPenfold
Mitwirkender/Mitwirkende

Using Custom Code to get activity dates in contact workflow

I'm trying to create a workflow that reminds sales reps to mark meetings completed after the fact, but using last activity date in combination with some custom dynamic date fields (Today's date, Yesterday's date) doesn't resolve the issue as I can't specify the type of activity for the last activity date, so when a rep sends an email or any other activity is added to the contact record, the contact enrols in the workflow (based on the other enrolment criteria like meeting outcome is scheduled etc.).

I think the only way I'm going to be able to resolve the issue is to find a way of getting the "Meeting end time" property from the activity into a contact property, so that I can then use the "is after another property" function to compare the end time and today's date. My understanding is that it is possible to pull data from properties on associated objects through the custom code function, but I'm not a developer myself and playing around a little with GPT to write something hasn't got me anything that works. 

Any ideas on how this can be achieved?

For reference, here's what GPT produced: 

const object_typeid = '0-4'; // The objecttypeid for activities
const contact_id = '{your_contact_id}'; // Replace with the actual contact ID

hubspotClient.crm.contacts.associationsApi.getAll(contact_id, object_typeid)
.then(function(results) {
const associatedActivities = results.body.results;

// Filter meeting activities
const meetingActivities = associatedActivities.filter(activity => activity.properties && activity.properties['Meeting end time']);

// Sort by meeting end time in descending order
meetingActivities.sort((a, b) => {
return new Date(b.properties['Meeting end time']) - new Date(a.properties['Meeting end time']);
});

// Get the most recent meeting activity
const mostRecentMeetingActivity = meetingActivities[0];
const meetingEndTime = mostRecentMeetingActivity.properties['Meeting end time'];

console.log('Most recent meeting end time:', meetingEndTime);
})
.catch(function(error) {
console.error('Error fetching associated activities:', error);
});

 

0 Upvotes
2 Antworten
Kevin-C
Trendsetter/-in | Partner
Trendsetter/-in | Partner

Using Custom Code to get activity dates in contact workflow

Hey @MPenfold 

 

EDIT: Found a better answer

 

You can create workflows that are based on meeting outcomes. Meaning you should be able to enroll engagements based on a outcome that is not "complete". This should get you moving rather quickly!

Happy to chat through a solution if needed!

Kevin Cornett - Sr. Solutions Architect @ BridgeRev
0 Upvotes
MPenfold
Mitwirkender/Mitwirkende

Using Custom Code to get activity dates in contact workflow

Hi @Kevin-C , 

Thanks for helping me out!

I've got the meeting outcome in my enrolment criteria but the issue is that I only want to trigger the task after the meeting end date has passed, so that I'm not creating the task reminder before the meeting has even happened. However, there's no way of using the Meeting End Date (or any of the other meeting properties) in conjunction with a contact property i.e. Meeting End Date is after Today's Date (a custom property dynamically updated on the Contact record). 

Your previous suggestion, to use the Contact time based workflow would work if all our meetings were booked through the HubSpot meetings tool, but unfortunately we also use calendly which integrates with HubSpot to create a meeting but, as I understand it, doesn't trigger the "Date of last meeting booked in meetings tool" criteria. 

Keen to jump on a call and chat through a solution though, really appreciate your help! How do we set that up?



What was

0 Upvotes