I have at ticket based workflow where I create a task and would like to associate it with a contact and the ticket that created it.
For the ‘property to include code’ it would be really convenient to be able to pull from other available data sources like associated contact’s record ID. I can add the data source but all its properties are grayed out.
Is there an alternative way to pass this associated contact ID into my custom code? Or am I left with having to traverse associations to my ticket via API.
You could try putting the associated Contact ID in a Format Data workflow action, in Custom Mode with no action like below:
Then you can pass this into the custom code action as an action output:
Wow that’s such a simple hacky workaround but I’ll probably use it a lot. Thanks for the tip! Wish there was a way to label that block to make it more readable.
I just went ahead and did the API call with this to get the associated contact ID:
async function getContactRecordId(client, ticketId) {
// associations doc: https://developers.hubspot.com/docs/api/crm/associations
const objectType = "ticket";
const objectId = ticketId;
const toObjectType = "contact";
const after = undefined;
const limit = 2;
if (objectId) {
try {
const apiResponse = await client.crm.associations.v4.basicApi.getPage(objectType, objectId, toObjectType, after, limit);
const associations = apiResponse.results;
if (associations.length > 0) {
const contactId = associations[0].toObjectId;
console.log(`Ticket ID ${ticketId} has associated Contact ID: ${contactId}`);
return contactId;
}
} catch (e) {
e.message === 'HTTP request failed'
? console.error(JSON.stringify(e.response, null, 2))
: console.error(e)
}
} else {
console.error('No ticket ID provided, cannot get associated contact ID.');
}
return null;
}
No worries - definitely a little hacky, but gets the job done while reducing the number of API calls if you’re expecting a high volume of workflow enrolments!