Hello,
If someone can help me identify why my custom code is not working for a Deal Workflow to Create a Ticket and bring Ticket Properties I need.
We are building a custom HubSpot workflow that:
- Triggers when a quote is marked “Ready for Booking” and hasn’t been signed yet.
- Creates a ticket to initiate order entry.
- Automatically populates ticket fields with key deal data:
-
Earliest start date from the quote’s line items
-
Company’s internal NavigaID (custom company property)
But it the fields are coming back empty on the ticket.
This is what is my logic:
-
Take the deal ID (hs_object_id)
-
Fetch all quotes associated with the deal
-
Sort them to find the most recent quote
-
Retrieve the line items associated with that quote
-
Identify the earliest start date
-
Return it for use in the workflow
I have a secret token that has these scopes:-
crm.objects.deals.read
-
crm.objects.quotes.read
-
crm.objects.line_items.read
-
crm.schemas.line_items.read
-
crm.objects.companies.read
-
crm.associations.read
<strong>**Here is the code I am using:** </strong> const hubspot = require('@hubspot/api-client'); exports.main = async (event, callback) => { const hs = new hubspot.Client({ accessToken: process.env.Line\_Item\_API }); const dealId = event.inputFields\['hs\_object\_id']; let debugLog = "Step 1: Start\n"; try { // Step 2: Get quotes associated with the deal debugLog += "Step 2: Fetching associated quotes...\n"; const quoteResults = await hs.crm.deals.associationsApi.getAll(dealId, 'quotes'); const quotes = quoteResults.results \|\| \[]; debugLog += \`Quotes found: ${quotes.length}\n\`; if (quotes.length === 0) { debugLog += "No quotes found for deal.\n"; callback({ outputFields: { earliest\_start\_date: null, debug\_log: debugLog } }); return; } // Step 3: Use most recent quote const latestQuoteId = quotes\[0].id; debugLog += \`Using quote ID: ${latestQuoteId}\n\`; // Step 4: Get line items for the quote const lineItemResults = await hs.crm.quotes.associationsApi.getAll(latestQuoteId, 'line\_items'); const lineItems = lineItemResults.results \|\| \[]; debugLog += \`Line items found: ${lineItems.length}\n\`; if (lineItems.length === 0) { debugLog += "No line items found for quote.\n"; callback({ outputFields: { earliest\_start\_date: null, debug\_log: debugLog } }); return; } // Step 5: Fetch full details of line items to access start\_date const fullLineItems = await Promise.all( lineItems.map(item => hs.crm.lineItems.basicApi.getById(item.id)) ); const startDates = fullLineItems .map(res => res.body.properties?.start\_date) .filter(date => !!date) .sort(); if (startDates.length === 0) { debugLog += "No valid start dates found.\n"; callback({ outputFields: { earliest\_start\_date: null, debug\_log: debugLog } }); return; } const earliest = startDates\[0]; debugLog += \`Earliest start date: ${earliest}\n\`; callback({ outputFields: { earliest\_start\_date: earliest, debug\_log: debugLog } }); } catch (error) { debugLog += \`Error: ${error.message \|\| error.toString()}\n\`; callback({ outputFields: { earliest\_start\_date: null, debug\_log: debugLog } }); } };
-
-
-
