Ticket workflow custom code to create associated note
SOLVE
Hi All,
Just to preface i am a complete beginner with code. What i am trying to accomplish is a note being created on an enrolled ticket that contains special instruction on how to handle specific customers. the code i have cobbled together is as follows, (using a private app)
Ticket workflow custom code to create associated note
SOLVE
I have this working now with some trial and error.
const hubspot = require('@hubspot/api-client');
exports.main = async (event) => { const token = process.env.OPS_TOKEN; // Calls the Private app const ticketId = event.inputFields.ticketId; // Pulls the Ticket id into the code
if (!token) { console.error('OPS_TOKEN is not set'); return; }
if (!ticketId) { console.error('TICKET_ID is not set'); return; }
console.log('Using ticket ID:', ticketId);
const hubspotClient = new hubspot.Client({ "accessToken": token });
// Fetch the ticket information let ticket; try { ticket = await hubspotClient.crm.tickets.basicApi.getById(ticketId); console.log('Ticket retrieved:', JSON.stringify(ticket, null, 2)); } catch (e) { console.error('Error fetching ticket:', e); return; }
// Step 2: Use the ticket ID to create a note const properties = { "hs_timestamp": Date.now(), // Current time/date "hs_note_body": "testing note creation" // Edit this section with the required message };
const SimplePublicObjectInputForCreate = { associations: [{ "types": [{ "associationCategory": "HUBSPOT_DEFINED", "associationTypeId": 228 }], // Use correct association type ID for tickets "to": { "id": ticketId } }], properties };
Workflows Create note workflow action November 7, 2024
What is it?
You can now automatically create notes using the new "Create note" workflow action.
Why does it matter?
Notes are a versatile tool for adding important context to records, highlighting key information, or summarizing changes for your team. With the new "Create note" workflow action, you can now automate the addition of notes to records as part of any process. For instance, when handing a customer off to the onboarding team, you can use a workflow to automatically add a note summarizing the information gathered during the sales process. Any data from the workflow can be included in the note body, including enrolled record properties, associated record properties, and workflow run time data like action outputs.
How does it work?
To use the action, create a new workflow and set up your trigger.
Search workflow actions or view the CRM action category to find the "Create note" action Select the action and draft the note body Add personalization tokens from the enrolled record, associated record, or workflow action outputs to the note body as desired
The workflow automatically associates the note with the enrolled record.
Workflows Create note workflow action November 7, 2024
What is it?
You can now automatically create notes using the new "Create note" workflow action.
Why does it matter?
Notes are a versatile tool for adding important context to records, highlighting key information, or summarizing changes for your team. With the new "Create note" workflow action, you can now automate the addition of notes to records as part of any process. For instance, when handing a customer off to the onboarding team, you can use a workflow to automatically add a note summarizing the information gathered during the sales process. Any data from the workflow can be included in the note body, including enrolled record properties, associated record properties, and workflow run time data like action outputs.
How does it work?
To use the action, create a new workflow and set up your trigger.
Search workflow actions or view the CRM action category to find the "Create note" action Select the action and draft the note body Add personalization tokens from the enrolled record, associated record, or workflow action outputs to the note body as desired
The workflow automatically associates the note with the enrolled record.
Ticket workflow custom code to create associated note
SOLVE
I have this working now with some trial and error.
const hubspot = require('@hubspot/api-client');
exports.main = async (event) => { const token = process.env.OPS_TOKEN; // Calls the Private app const ticketId = event.inputFields.ticketId; // Pulls the Ticket id into the code
if (!token) { console.error('OPS_TOKEN is not set'); return; }
if (!ticketId) { console.error('TICKET_ID is not set'); return; }
console.log('Using ticket ID:', ticketId);
const hubspotClient = new hubspot.Client({ "accessToken": token });
// Fetch the ticket information let ticket; try { ticket = await hubspotClient.crm.tickets.basicApi.getById(ticketId); console.log('Ticket retrieved:', JSON.stringify(ticket, null, 2)); } catch (e) { console.error('Error fetching ticket:', e); return; }
// Step 2: Use the ticket ID to create a note const properties = { "hs_timestamp": Date.now(), // Current time/date "hs_note_body": "testing note creation" // Edit this section with the required message };
const SimplePublicObjectInputForCreate = { associations: [{ "types": [{ "associationCategory": "HUBSPOT_DEFINED", "associationTypeId": 228 }], // Use correct association type ID for tickets "to": { "id": ticketId } }], properties };
Ticket workflow custom code to create associated note
SOLVE
Hey, @MatBehr👋 That error looks like it's coming from the workflow not recognizing the objectId ","context":{"id":["hs_object_id"]},"category":"OBJECT_NOT_FOUND"}" I'd start by testing with a hard-coded value and then once successful, looking at how you are declaring the variable for `id`.
If you've already done this, please follow up here and we'll take another look.
Best,
Jaycee
HubSpot’s AI-powered customer agent resolves up to 50% of customer queries instantly, with some customers reaching up to 90% resolution rates. Learn More.
Did you know that the Community is available in other languages? Join regional conversations by changing your language settings !