Quick question for anyone who has used custom code inside of workflows. I am currently trying to copy the date of a specific meeting type to a field on the deal level. I’ve tried a workflow, but it doesn’t want to pull the data from this specific type of meeting, but all meetings.
Does anyone have experience with this? Or anyone know how to accomplish this?
Hey @JBortle - Theoretically, you should be able to utilise the value in the ‘Meeting type’ within your code to only stamp over the date value if the Meeting type is equal to that which you want it to be.
Alternatively, this is possible utilising Zapier:
I have created a small workflow with a coded action that retrieves specific data from the most recent meeting and copies that data to contact properties, so quite similar to what you want to achieve;
const axios = require('axios');
exports.main = async (event, callback) => {
const lastMeetingDate = event.inputFields['engagements_last_meeting_booked'];
const contactID = event.inputFields['hs_object_id'];
let location = event.inputFields['afspraak_locatie__single_line_tekst_'];
let type = event.inputFields['type_afspraak'];
let date = event.inputFields['afspraak_datum'];
let time = event.inputFields['afspraak_tijd'];
const associations = await axios({
method: 'get',
url: `https://api.hubapi.com/crm/v3/objects/contacts/${contactID}/associations/meetings/?limit=10`,
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${process.env.CONTACT_TOKEN}`
}
}).then((response) => {
if (response.data.results.length > 0) {
console.log(`Found ${response.data.results.length} meetings for contact ${contactID}`)
return response.data.results.map((result) => {
return {
id: result.id
}
})
} else {
return false
}
}).catch((error) => {
console.log(error)
})
if (associations) {
const data = {
properties: [
"hs_timestamp",
"hs_meeting_start_time",
"hs_meeting_location",
"hs_activity_type"
],
inputs: associations
}
const latestMeeting = await axios({
method: 'post',
url: `https://api.hubapi.com/crm/v3/objects/meetings/batch/read?archived=false`,
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${process.env.CONTACT_TOKEN}`
},
data: JSON.stringify(data)
}).then((response) => {
if (response.data.results) {
// Get the latest meeting
return response.data.results.reduce((a, b) => new Date(a.createdAt) > new Date(b.createdAt) ? a : b)
}
}).catch((error) => {
console.log(error.response.data)
})
if (latestMeeting) {
location = latestMeeting.properties.hs_meeting_location;
date = new Date(latestMeeting.properties.hs_meeting_start_time)
time = latestMeeting.properties.hs_meeting_start_time ? `${String((date.getHours() + 2)).padStart(2, '0')}:${String(date.getMinutes()).padStart(2, '0')}` : '';
await axios({
method: 'patch',
url: `https://api.hubapi.com/crm/v3/objects/contacts/${contactID}`,
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${process.env.CONTACT_TOKEN}`
},
data: JSON.stringify({
properties: {
afspraak_datum: new Date(date.getFullYear(), date.getMonth(), date.getDate())
}
})
}).then((response) => {
console.log(response.data)
}).catch((error) => {
console.log(error.data)
})
}
}
callback({
outputFields: {
location: location,
date: date,
time: time,
type: type,
}
});
}
So when retrieving the associated meetings, I only return the most recent one. You might have to do something similar based on what type of meeting you want to return.
I hope this helps!