<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Data Output Error Even Though It's Defined in Data Hub</title>
    <link>https://community.hubspot.com/t5/Data-Hub/Data-Output-Error-Even-Though-It-s-Defined/m-p/1191217#M3178</link>
    <description>&lt;P&gt;I am attempting to create a calculation on deal records that will sum the net amounts on all line items of a specific Product Type. Steps I've taken:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Created a private app to view line items, products, deals and edit deals&lt;/LI&gt;
&lt;LI&gt;Created a property &amp;lt;def_amount&amp;gt; that is a currency property&lt;/LI&gt;
&lt;LI&gt;Defined def_amount&lt;/LI&gt;
&lt;LI&gt;Added def_amount as a data output&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;I'm not a dev so excuse the likely **bleep** code, but the code is below. When I test the action, I keep getting the error that def_amount is not defined in the code. What is going on?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;const hubspot = require('@hubspot/api-client');&lt;/P&gt;
&lt;P&gt;const MATCH_VALUE = 'DEFENDIFY';&lt;BR /&gt;const PRODUCT_TYPE_PROP = 'hs_product_type';&lt;/P&gt;
&lt;P&gt;// Net total preference order&lt;BR /&gt;const NET_PRIMARY = 'amount'; // HubSpot line-item net total&lt;BR /&gt;const NET_FALLBACK = 'hs_total_amount'; // fallback if present&lt;/P&gt;
&lt;P&gt;// Fallback compute fields&lt;BR /&gt;const PRICE_PROPS = ['price', 'hs_price'];&lt;BR /&gt;const QTY_PROP = 'quantity';&lt;BR /&gt;const DISC_AMT_PROP = 'hs_discount_amount';&lt;BR /&gt;const DISC_PCT_PROP = 'hs_discount_percentage';&lt;/P&gt;
&lt;P&gt;const normalize = v =&amp;gt; String(v ?? '').trim().toUpperCase();&lt;BR /&gt;const toNumber = v =&amp;gt; {&lt;BR /&gt;if (v == null) return 0;&lt;BR /&gt;const n = parseFloat(String(v).replace(/[^0-9.\-]/g, ''));&lt;BR /&gt;return Number.isFinite(n) ? n : 0;&lt;BR /&gt;};&lt;/P&gt;
&lt;P&gt;exports.main = async (event) =&amp;gt; {&lt;BR /&gt;const client = new hubspot.Client({ accessToken: process.env.DEFENDIFY_CALC });&lt;BR /&gt;const dealId = event.object.objectId;&lt;/P&gt;
&lt;P&gt;try {&lt;BR /&gt;const deal = await client.crm.deals.basicApi.getById(dealId, undefined, undefined, ['line_items']);&lt;BR /&gt;const lineItemIds = (deal?.associations?.line_items?.results || []).map(x =&amp;gt; String(x.id)).filter(Boolean);&lt;BR /&gt;if (lineItemIds.length === 0) return { outputFields: { def_amount: 0 } };&lt;/P&gt;
&lt;P&gt;const propsToFetch = [&lt;BR /&gt;PRODUCT_TYPE_PROP, NET_PRIMARY, NET_FALLBACK,&lt;BR /&gt;...PRICE_PROPS, QTY_PROP, DISC_AMT_PROP, DISC_PCT_PROP,&lt;BR /&gt;];&lt;BR /&gt;const batch = await client.crm.lineItems.batchApi.read({&lt;BR /&gt;properties: propsToFetch,&lt;BR /&gt;inputs: lineItemIds.map(id =&amp;gt; ({ id })),&lt;BR /&gt;});&lt;/P&gt;
&lt;P&gt;let sum = 0;&lt;BR /&gt;for (const row of (batch?.results || [])) {&lt;BR /&gt;const p = row?.properties || {};&lt;BR /&gt;if (normalize(p[PRODUCT_TYPE_PROP]) !== MATCH_VALUE) continue;&lt;/P&gt;
&lt;P&gt;let net = toNumber(p[NET_PRIMARY]);&lt;BR /&gt;if (!(net &amp;gt; 0)) net = toNumber(p[NET_FALLBACK]);&lt;/P&gt;
&lt;P&gt;if (!(net &amp;gt; 0)) {&lt;BR /&gt;const qty = toNumber(p[QTY_PROP]) || 1;&lt;BR /&gt;const unit = PRICE_PROPS.reduce((acc, k) =&amp;gt; (acc &amp;gt; 0 ? acc : toNumber(p[k])), 0) || 0;&lt;BR /&gt;const pre = unit * qty;&lt;BR /&gt;const discAmt = toNumber(p[DISC_AMT_PROP]);&lt;BR /&gt;const discPct = toNumber(p[DISC_PCT_PROP]);&lt;BR /&gt;const totalDisc = discAmt &amp;gt; 0 ? discAmt * qty : (discPct &amp;gt; 0 ? pre * (discPct / 100) : 0);&lt;BR /&gt;net = Math.max(0, pre - totalDisc);&lt;BR /&gt;}&lt;/P&gt;
&lt;P&gt;sum += net;&lt;BR /&gt;}&lt;/P&gt;
&lt;P&gt;return { outputFields: { def_amount: sum } };&lt;BR /&gt;} catch {&lt;BR /&gt;return { outputFields: { def_amount: 0 } };&lt;BR /&gt;}&lt;BR /&gt;};&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 20 Aug 2025 19:59:35 GMT</pubDate>
    <dc:creator>JoeBurchard</dc:creator>
    <dc:date>2025-08-20T19:59:35Z</dc:date>
    <item>
      <title>Data Output Error Even Though It's Defined</title>
      <link>https://community.hubspot.com/t5/Data-Hub/Data-Output-Error-Even-Though-It-s-Defined/m-p/1191217#M3178</link>
      <description>&lt;P&gt;I am attempting to create a calculation on deal records that will sum the net amounts on all line items of a specific Product Type. Steps I've taken:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Created a private app to view line items, products, deals and edit deals&lt;/LI&gt;
&lt;LI&gt;Created a property &amp;lt;def_amount&amp;gt; that is a currency property&lt;/LI&gt;
&lt;LI&gt;Defined def_amount&lt;/LI&gt;
&lt;LI&gt;Added def_amount as a data output&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;I'm not a dev so excuse the likely **bleep** code, but the code is below. When I test the action, I keep getting the error that def_amount is not defined in the code. What is going on?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;const hubspot = require('@hubspot/api-client');&lt;/P&gt;
&lt;P&gt;const MATCH_VALUE = 'DEFENDIFY';&lt;BR /&gt;const PRODUCT_TYPE_PROP = 'hs_product_type';&lt;/P&gt;
&lt;P&gt;// Net total preference order&lt;BR /&gt;const NET_PRIMARY = 'amount'; // HubSpot line-item net total&lt;BR /&gt;const NET_FALLBACK = 'hs_total_amount'; // fallback if present&lt;/P&gt;
&lt;P&gt;// Fallback compute fields&lt;BR /&gt;const PRICE_PROPS = ['price', 'hs_price'];&lt;BR /&gt;const QTY_PROP = 'quantity';&lt;BR /&gt;const DISC_AMT_PROP = 'hs_discount_amount';&lt;BR /&gt;const DISC_PCT_PROP = 'hs_discount_percentage';&lt;/P&gt;
&lt;P&gt;const normalize = v =&amp;gt; String(v ?? '').trim().toUpperCase();&lt;BR /&gt;const toNumber = v =&amp;gt; {&lt;BR /&gt;if (v == null) return 0;&lt;BR /&gt;const n = parseFloat(String(v).replace(/[^0-9.\-]/g, ''));&lt;BR /&gt;return Number.isFinite(n) ? n : 0;&lt;BR /&gt;};&lt;/P&gt;
&lt;P&gt;exports.main = async (event) =&amp;gt; {&lt;BR /&gt;const client = new hubspot.Client({ accessToken: process.env.DEFENDIFY_CALC });&lt;BR /&gt;const dealId = event.object.objectId;&lt;/P&gt;
&lt;P&gt;try {&lt;BR /&gt;const deal = await client.crm.deals.basicApi.getById(dealId, undefined, undefined, ['line_items']);&lt;BR /&gt;const lineItemIds = (deal?.associations?.line_items?.results || []).map(x =&amp;gt; String(x.id)).filter(Boolean);&lt;BR /&gt;if (lineItemIds.length === 0) return { outputFields: { def_amount: 0 } };&lt;/P&gt;
&lt;P&gt;const propsToFetch = [&lt;BR /&gt;PRODUCT_TYPE_PROP, NET_PRIMARY, NET_FALLBACK,&lt;BR /&gt;...PRICE_PROPS, QTY_PROP, DISC_AMT_PROP, DISC_PCT_PROP,&lt;BR /&gt;];&lt;BR /&gt;const batch = await client.crm.lineItems.batchApi.read({&lt;BR /&gt;properties: propsToFetch,&lt;BR /&gt;inputs: lineItemIds.map(id =&amp;gt; ({ id })),&lt;BR /&gt;});&lt;/P&gt;
&lt;P&gt;let sum = 0;&lt;BR /&gt;for (const row of (batch?.results || [])) {&lt;BR /&gt;const p = row?.properties || {};&lt;BR /&gt;if (normalize(p[PRODUCT_TYPE_PROP]) !== MATCH_VALUE) continue;&lt;/P&gt;
&lt;P&gt;let net = toNumber(p[NET_PRIMARY]);&lt;BR /&gt;if (!(net &amp;gt; 0)) net = toNumber(p[NET_FALLBACK]);&lt;/P&gt;
&lt;P&gt;if (!(net &amp;gt; 0)) {&lt;BR /&gt;const qty = toNumber(p[QTY_PROP]) || 1;&lt;BR /&gt;const unit = PRICE_PROPS.reduce((acc, k) =&amp;gt; (acc &amp;gt; 0 ? acc : toNumber(p[k])), 0) || 0;&lt;BR /&gt;const pre = unit * qty;&lt;BR /&gt;const discAmt = toNumber(p[DISC_AMT_PROP]);&lt;BR /&gt;const discPct = toNumber(p[DISC_PCT_PROP]);&lt;BR /&gt;const totalDisc = discAmt &amp;gt; 0 ? discAmt * qty : (discPct &amp;gt; 0 ? pre * (discPct / 100) : 0);&lt;BR /&gt;net = Math.max(0, pre - totalDisc);&lt;BR /&gt;}&lt;/P&gt;
&lt;P&gt;sum += net;&lt;BR /&gt;}&lt;/P&gt;
&lt;P&gt;return { outputFields: { def_amount: sum } };&lt;BR /&gt;} catch {&lt;BR /&gt;return { outputFields: { def_amount: 0 } };&lt;BR /&gt;}&lt;BR /&gt;};&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Aug 2025 19:59:35 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/Data-Hub/Data-Output-Error-Even-Though-It-s-Defined/m-p/1191217#M3178</guid>
      <dc:creator>JoeBurchard</dc:creator>
      <dc:date>2025-08-20T19:59:35Z</dc:date>
    </item>
    <item>
      <title>Re: Data Output Error Even Though It's Defined</title>
      <link>https://community.hubspot.com/t5/Data-Hub/Data-Output-Error-Even-Though-It-s-Defined/m-p/1191269#M3179</link>
      <description>&lt;P&gt;Below is an image of the output&lt;BR /&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2025-08-20 155916.png" style="width: 426px;"&gt;&lt;img src="https://community.hubspot.com/t5/image/serverpage/image-id/153685iB53AF373233491FB/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screenshot 2025-08-20 155916.png" alt="Screenshot 2025-08-20 155916.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Aug 2025 22:07:52 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/Data-Hub/Data-Output-Error-Even-Though-It-s-Defined/m-p/1191269#M3179</guid>
      <dc:creator>JoeBurchard</dc:creator>
      <dc:date>2025-08-20T22:07:52Z</dc:date>
    </item>
    <item>
      <title>Re: Data Output Error Even Though It's Defined</title>
      <link>https://community.hubspot.com/t5/Data-Hub/Data-Output-Error-Even-Though-It-s-Defined/m-p/1193989#M3185</link>
      <description>&lt;P&gt;Hey&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/348705"&gt;@JoeBurchard&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I'm not a developer myself, I wish I could help with the code &lt;span class="lia-unicode-emoji" title=":grinning_face_with_smiling_eyes:"&gt;😄&lt;/span&gt;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;But, have you tried a rollup field instead of a code? That seems to be a much easier solution. Should look like this on the deal level.&lt;BR /&gt;&lt;BR /&gt;While you can't add line item name as a condition (which I find weird), perhaps if you scroll through the options available, you'll find a fit identifier or even create a custom identifier.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="KareemT_0-1756317518014.png" style="width: 400px;"&gt;&lt;img src="https://community.hubspot.com/t5/image/serverpage/image-id/154200iC8FD68CC263500AC/image-size/medium?v=v2&amp;amp;px=400" role="button" title="KareemT_0-1756317518014.png" alt="KareemT_0-1756317518014.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Aug 2025 18:02:04 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/Data-Hub/Data-Output-Error-Even-Though-It-s-Defined/m-p/1193989#M3185</guid>
      <dc:creator>KareemT</dc:creator>
      <dc:date>2025-08-27T18:02:04Z</dc:date>
    </item>
    <item>
      <title>Re: Data Output Error Even Though It's Defined</title>
      <link>https://community.hubspot.com/t5/Data-Hub/Data-Output-Error-Even-Though-It-s-Defined/m-p/1234613#M3332</link>
      <description>&lt;P&gt;Hey &lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/348705"&gt;@JoeBurchard&lt;/a&gt;&amp;nbsp;, the code you pasted looks fine for returning an output, so when HubSpot says def_amount is not defined, it’s usually not complaining about your math. It’s complaining about a mismatch between what HubSpot thinks the output is called and what your code returns.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In custom code actions, the output field “name” is not your deal property label and it’s not the display name you see in the UI. HubSpot uses the output field’s internal name, and it has to match the key you return in outputFields exactly (including case, no spaces).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So double check the output definition in the action: if the output is actually def_amount_1, def_amount__c, or has a trailing space, returning { def_amount: sum } will throw weird “not defined” style errors even though your JS object is valid. This is the doc section that describes the output contract (&lt;A href="https://developers.hubspot.com/docs/api-reference/automation-actions-v4-v4/custom-code-actions" target="_blank"&gt;https://developers.hubspot.com/docs/api-reference/automation-actions-v4-v4/custom-code-actions&lt;/A&gt; )&lt;/P&gt;
&lt;P data-start="1217" data-end="1610"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One more gotcha: you named the deal property &amp;lt;def_amount&amp;gt; in your post. If you literally used angle brackets anywhere (property name, output name, or mapping), HubSpot will sanitize the internal name and it won’t be what you expect. The safe path is: confirm the deal property internal name in settings, then confirm the custom code action output internal name, then make them match exactly.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Small debugging tip: change your catch to catch (e) { console.log(e); return { outputFields: { def_amount: 0 } }; } so you can see the real runtime error in the test output.&lt;/P&gt;
&lt;P&gt;Quick question: is the error happening in the custom code action test run, or only when you map the output to the deal property afterward? That determines whether it’s an output-name mismatch or a mapping issue.&lt;/P&gt;</description>
      <pubDate>Tue, 16 Dec 2025 18:52:00 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/Data-Hub/Data-Output-Error-Even-Though-It-s-Defined/m-p/1234613#M3332</guid>
      <dc:creator>RubenBurdin</dc:creator>
      <dc:date>2025-12-16T18:52:00Z</dc:date>
    </item>
  </channel>
</rss>

