<?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 Custom Object Code Issue in APIs &amp; Integrations</title>
    <link>https://community.hubspot.com/t5/APIs-Integrations/Custom-Object-Code-Issue/m-p/1166473#M82706</link>
    <description>&lt;P&gt;Hi all, I built a custom object that records activites (page view, form submission, ad submission, etc) I created the custom object to store some of these native activites along with other custom events not native in HubSpot, to use in journey mapping. The client wants to identify the first activity based on the activity (event) date. So as these records are created, I created a workflow with the following code to mark (check) if the event was the first (custom property called "First Scoring Event". The logic is if no other event record exists assocated to the contact then set First Scoing Event to true. If there is a an exisisting record then do nothing. I created a workflow to populate another event record custome property call Associated contact ID. The workflow copies the Contact Record ID to the associated event record property. The code below works in setting the first record First Scoring Record to true but when another record is created, it can't find any other records associated to the same contact, thus changes the&amp;nbsp;First Scoring Record to true on the second record when it should do nothing. Can anyone see what I'm missing? Thanks!&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;const hubspot = require('@hubspot/api-client');&lt;/P&gt;
&lt;P&gt;exports.main = async (event, callback) =&amp;gt; {&lt;BR /&gt;const hubspotClient = new hubspot.Client({&lt;BR /&gt;accessToken: process.env.scoringEvents,&lt;BR /&gt;numberOfApiCallRetries: 3,&lt;BR /&gt;});&lt;/P&gt;
&lt;P&gt;const OBJECT_TYPE_ID = '2-44054457';&lt;BR /&gt;const PROPERTY = 'associated_contact_id';&lt;/P&gt;
&lt;P&gt;const scoringEventId = (event.inputFields['hs_object_id'] || '').trim();&lt;BR /&gt;const contactId = (event.inputFields[PROPERTY] || '').trim();&lt;/P&gt;
&lt;P&gt;if (!scoringEventId || !contactId) {&lt;BR /&gt;console.log('&lt;span class="lia-unicode-emoji" title=":cross_mark:"&gt;❌&lt;/span&gt; Missing scoringEventId or associated_contact_id. Exiting.');&lt;BR /&gt;return callback({ outputFields: {} });&lt;BR /&gt;}&lt;/P&gt;
&lt;P&gt;console.log(`&lt;span class="lia-unicode-emoji" title=":magnifying_glass_tilted_left:"&gt;🔍&lt;/span&gt; Checking if any scoring event already exists with ${PROPERTY} = ${contactId}`);&lt;/P&gt;
&lt;P&gt;try {&lt;BR /&gt;const response = await hubspotClient.crm.objects.basicApi.getPage(&lt;BR /&gt;OBJECT_TYPE_ID,&lt;BR /&gt;100,&lt;BR /&gt;undefined,&lt;BR /&gt;[PROPERTY]&lt;BR /&gt;);&lt;/P&gt;
&lt;P&gt;const events = response.results || [];&lt;/P&gt;
&lt;P&gt;events.forEach(e =&amp;gt; {&lt;BR /&gt;console.log(`🧪 Event ${e.id} → ${PROPERTY}: ${e.properties[PROPERTY]}`);&lt;BR /&gt;});&lt;/P&gt;
&lt;P&gt;const match = events.find(e =&amp;gt;&lt;BR /&gt;String(e.id) !== scoringEventId &amp;amp;&amp;amp;&lt;BR /&gt;String(e.properties[PROPERTY] || '').trim() === contactId&lt;BR /&gt;);&lt;/P&gt;
&lt;P&gt;if (match) {&lt;BR /&gt;console.log(`&lt;span class="lia-unicode-emoji" title=":warning:"&gt;⚠️&lt;/span&gt; Another event exists for contact ${contactId} — skipping update`);&lt;BR /&gt;return callback({ outputFields: {} });&lt;BR /&gt;}&lt;/P&gt;
&lt;P&gt;await hubspotClient.crm.objects.basicApi.update(OBJECT_TYPE_ID, scoringEventId, {&lt;BR /&gt;properties: {&lt;BR /&gt;first_scoring_event: true&lt;BR /&gt;}&lt;BR /&gt;});&lt;/P&gt;
&lt;P&gt;console.log(`&lt;span class="lia-unicode-emoji" title=":white_heavy_check_mark:"&gt;✅&lt;/span&gt; Marked event ${scoringEventId} as first_scoring_event = true`);&lt;BR /&gt;callback({ outputFields: {} });&lt;/P&gt;
&lt;P&gt;} catch (err) {&lt;BR /&gt;console.error('&lt;span class="lia-unicode-emoji" title=":police_car_light:"&gt;🚨&lt;/span&gt; Error during update:', err.response?.body || err.message || err);&lt;BR /&gt;callback({ outputFields: {} });&lt;BR /&gt;}&lt;BR /&gt;};&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 18 Jun 2025 21:28:03 GMT</pubDate>
    <dc:creator>DZoladz36</dc:creator>
    <dc:date>2025-06-18T21:28:03Z</dc:date>
    <item>
      <title>Custom Object Code Issue</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Custom-Object-Code-Issue/m-p/1166473#M82706</link>
      <description>&lt;P&gt;Hi all, I built a custom object that records activites (page view, form submission, ad submission, etc) I created the custom object to store some of these native activites along with other custom events not native in HubSpot, to use in journey mapping. The client wants to identify the first activity based on the activity (event) date. So as these records are created, I created a workflow with the following code to mark (check) if the event was the first (custom property called "First Scoring Event". The logic is if no other event record exists assocated to the contact then set First Scoing Event to true. If there is a an exisisting record then do nothing. I created a workflow to populate another event record custome property call Associated contact ID. The workflow copies the Contact Record ID to the associated event record property. The code below works in setting the first record First Scoring Record to true but when another record is created, it can't find any other records associated to the same contact, thus changes the&amp;nbsp;First Scoring Record to true on the second record when it should do nothing. Can anyone see what I'm missing? Thanks!&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;const hubspot = require('@hubspot/api-client');&lt;/P&gt;
&lt;P&gt;exports.main = async (event, callback) =&amp;gt; {&lt;BR /&gt;const hubspotClient = new hubspot.Client({&lt;BR /&gt;accessToken: process.env.scoringEvents,&lt;BR /&gt;numberOfApiCallRetries: 3,&lt;BR /&gt;});&lt;/P&gt;
&lt;P&gt;const OBJECT_TYPE_ID = '2-44054457';&lt;BR /&gt;const PROPERTY = 'associated_contact_id';&lt;/P&gt;
&lt;P&gt;const scoringEventId = (event.inputFields['hs_object_id'] || '').trim();&lt;BR /&gt;const contactId = (event.inputFields[PROPERTY] || '').trim();&lt;/P&gt;
&lt;P&gt;if (!scoringEventId || !contactId) {&lt;BR /&gt;console.log('&lt;span class="lia-unicode-emoji" title=":cross_mark:"&gt;❌&lt;/span&gt; Missing scoringEventId or associated_contact_id. Exiting.');&lt;BR /&gt;return callback({ outputFields: {} });&lt;BR /&gt;}&lt;/P&gt;
&lt;P&gt;console.log(`&lt;span class="lia-unicode-emoji" title=":magnifying_glass_tilted_left:"&gt;🔍&lt;/span&gt; Checking if any scoring event already exists with ${PROPERTY} = ${contactId}`);&lt;/P&gt;
&lt;P&gt;try {&lt;BR /&gt;const response = await hubspotClient.crm.objects.basicApi.getPage(&lt;BR /&gt;OBJECT_TYPE_ID,&lt;BR /&gt;100,&lt;BR /&gt;undefined,&lt;BR /&gt;[PROPERTY]&lt;BR /&gt;);&lt;/P&gt;
&lt;P&gt;const events = response.results || [];&lt;/P&gt;
&lt;P&gt;events.forEach(e =&amp;gt; {&lt;BR /&gt;console.log(`🧪 Event ${e.id} → ${PROPERTY}: ${e.properties[PROPERTY]}`);&lt;BR /&gt;});&lt;/P&gt;
&lt;P&gt;const match = events.find(e =&amp;gt;&lt;BR /&gt;String(e.id) !== scoringEventId &amp;amp;&amp;amp;&lt;BR /&gt;String(e.properties[PROPERTY] || '').trim() === contactId&lt;BR /&gt;);&lt;/P&gt;
&lt;P&gt;if (match) {&lt;BR /&gt;console.log(`&lt;span class="lia-unicode-emoji" title=":warning:"&gt;⚠️&lt;/span&gt; Another event exists for contact ${contactId} — skipping update`);&lt;BR /&gt;return callback({ outputFields: {} });&lt;BR /&gt;}&lt;/P&gt;
&lt;P&gt;await hubspotClient.crm.objects.basicApi.update(OBJECT_TYPE_ID, scoringEventId, {&lt;BR /&gt;properties: {&lt;BR /&gt;first_scoring_event: true&lt;BR /&gt;}&lt;BR /&gt;});&lt;/P&gt;
&lt;P&gt;console.log(`&lt;span class="lia-unicode-emoji" title=":white_heavy_check_mark:"&gt;✅&lt;/span&gt; Marked event ${scoringEventId} as first_scoring_event = true`);&lt;BR /&gt;callback({ outputFields: {} });&lt;/P&gt;
&lt;P&gt;} catch (err) {&lt;BR /&gt;console.error('&lt;span class="lia-unicode-emoji" title=":police_car_light:"&gt;🚨&lt;/span&gt; Error during update:', err.response?.body || err.message || err);&lt;BR /&gt;callback({ outputFields: {} });&lt;BR /&gt;}&lt;BR /&gt;};&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 18 Jun 2025 21:28:03 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Custom-Object-Code-Issue/m-p/1166473#M82706</guid>
      <dc:creator>DZoladz36</dc:creator>
      <dc:date>2025-06-18T21:28:03Z</dc:date>
    </item>
    <item>
      <title>Re: Custom Object Code Issue</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Custom-Object-Code-Issue/m-p/1166735#M82720</link>
      <description>&lt;P&gt;Hi &lt;SPAN style="background: var(--ck-color-mention-background); color: var(--ck-color-mention-text);"&gt;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/684753"&gt;@DZoladz36&lt;/a&gt;&lt;/SPAN&gt;, I hope that you are well!&lt;BR /&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for asking the HubSpot Community!&lt;BR /&gt;&lt;BR /&gt;Here is a documentation on the topic "&lt;A href="https://developers.hubspot.com/docs/guides/api/crm/extensions/timeline" target="_blank"&gt;Timeline Events&lt;/A&gt;", just for information.&lt;BR /&gt;&lt;BR /&gt;Also, I'd love to invite our Top Experts and Community Members to join this discussion: Hi &lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/17186"&gt;@Anton&lt;/a&gt;, &lt;SPAN style="background: var(--ck-color-mention-background); color: var(--ck-color-mention-text);"&gt;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/601366"&gt;@sylvain_tirreau&lt;/a&gt;&lt;/SPAN&gt;, &lt;SPAN style="background: var(--ck-color-mention-background); color: var(--ck-color-mention-text);"&gt;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/324811"&gt;@zach_threadint&lt;/a&gt;&lt;/SPAN&gt; and &lt;SPAN style="background: var(--ck-color-mention-background); color: var(--ck-color-mention-text);"&gt;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/764582"&gt;@Jarro&lt;/a&gt;&lt;/SPAN&gt; do you have any tips to share with &lt;SPAN style="background: var(--ck-color-mention-background); color: var(--ck-color-mention-text);"&gt;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/684753"&gt;@DZoladz36&lt;/a&gt;&lt;/SPAN&gt;, please?&lt;BR /&gt;&lt;BR /&gt;Have a beautiful day and thanks so much for your help! &lt;span class="lia-unicode-emoji" title=":red_heart:"&gt;❤️&lt;/span&gt;&lt;BR /&gt;Bérangère&lt;/P&gt;</description>
      <pubDate>Thu, 19 Jun 2025 12:03:05 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Custom-Object-Code-Issue/m-p/1166735#M82720</guid>
      <dc:creator>BérangèreL</dc:creator>
      <dc:date>2025-06-19T12:03:05Z</dc:date>
    </item>
    <item>
      <title>Re: Custom Object Code Issue</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Custom-Object-Code-Issue/m-p/1173639#M83061</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/684753"&gt;@DZoladz36&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;const response = await hubspotClient.crm.objects.basicApi.getPage(
      OBJECT_TYPE_ID,
      100,
      undefined,
      [PROPERTY]
    );&lt;/LI-CODE&gt;&lt;P&gt;In this snippet of code, you only retrieve the last 100 events without navigating through all the pages: if between the contact's first event and the second, 100 events were created for all contacts combined, your first event will no longer be visible. You have to navigate through all the pages, but it's time-consuming.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;There's a more efficient way to do what you want: retrieve only the events related to your current contact.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example (untested code):&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;    const searchRequest = {
      filterGroups: [{
        filters: [{
          propertyName: PROPERTY,
          operator: 'EQ',
          value: contactId
        }, {
          propertyName: 'hs_object_id',
          operator: 'NEQ',
          value: scoringEventId
        }]
      }],
      limit: 1
    };

    const { total } = await hubspotClient.crm.objects.searchApi.doSearch(
      OBJECT_TYPE_ID,
      searchRequest
    );
    
    if (total &amp;gt; 0) {
      console.log(`Event exists for the contact ${contactId}`);
      return callback({ outputFields: {} });
    }&lt;/LI-CODE&gt;&lt;P&gt;,&amp;nbsp;but it's time-consuming&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 07 Jul 2025 14:05:44 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Custom-Object-Code-Issue/m-p/1173639#M83061</guid>
      <dc:creator>sylvain_tirreau</dc:creator>
      <dc:date>2025-07-07T14:05:44Z</dc:date>
    </item>
  </channel>
</rss>

