<?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 Coded Workflow - find line item associations in Data Hub</title>
    <link>https://community.hubspot.com/t5/Data-Hub/Custom-Coded-Workflow-find-line-item-associations/m-p/901055#M2003</link>
    <description>&lt;P&gt;I have some experience in R but nearly none in JavaScript/Python. In scowering the internet for hours this is the best I've came up with with finding line item associations with a deal. I want to be able to use the line items and their information later in the workflow to attach to a new deal.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;What am I missing?&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;const hubspot = require('@hubspot/api-client');

exports.main = (event, callback) =&amp;gt; {

    const hubspotClient = new hubspot.Client({
        apiKey: process.env.hapikey
    });
    
    // First, make a call to get deal associations  
    hubspotClient.crm.deals.associationsApi.getAll(event.object.objectId, 'line_item').then((results) =&amp;gt; {
        let lineItemPromises = results.body.results.map(item =&amp;gt; {
            // For each line item, get its details
            return hubspotClient.crm.lineItems.basicApi.getById(item.id, ['amount']).then(results =&amp;gt; {
                return results.body; // Return the details of the line item
            }).catch(err =&amp;gt; {
                console.error(`Error fetching details for line item ${item.id}:`, err.message);
                return null; // Return null or handle as appropriate for your needs
            });
        });
        
        // Resolve all promises to get details of each line item
        Promise.all(lineItemPromises).then(lineItemDetails =&amp;gt; {
            console.log(lineItemDetails); // Log the details of all line items
            
            // Further processing can be done here with lineItemDetails
            // For example, filtering high-value line items, aggregating data, etc.
            
            callback({}); // Complete the function
        }).catch(err =&amp;gt; {
            console.error('Error processing line items:', err.message);
            callback({}); // Complete the function, consider passing error details
        });

    }).catch(err =&amp;gt; {
        console.error('Error fetching line item associations:', err.message);
        callback({}); // Complete the function, consider passing error details
    });
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 05 Jan 2024 00:28:49 GMT</pubDate>
    <dc:creator>AOber</dc:creator>
    <dc:date>2024-01-05T00:28:49Z</dc:date>
    <item>
      <title>Custom Coded Workflow - find line item associations</title>
      <link>https://community.hubspot.com/t5/Data-Hub/Custom-Coded-Workflow-find-line-item-associations/m-p/901055#M2003</link>
      <description>&lt;P&gt;I have some experience in R but nearly none in JavaScript/Python. In scowering the internet for hours this is the best I've came up with with finding line item associations with a deal. I want to be able to use the line items and their information later in the workflow to attach to a new deal.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;What am I missing?&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;const hubspot = require('@hubspot/api-client');

exports.main = (event, callback) =&amp;gt; {

    const hubspotClient = new hubspot.Client({
        apiKey: process.env.hapikey
    });
    
    // First, make a call to get deal associations  
    hubspotClient.crm.deals.associationsApi.getAll(event.object.objectId, 'line_item').then((results) =&amp;gt; {
        let lineItemPromises = results.body.results.map(item =&amp;gt; {
            // For each line item, get its details
            return hubspotClient.crm.lineItems.basicApi.getById(item.id, ['amount']).then(results =&amp;gt; {
                return results.body; // Return the details of the line item
            }).catch(err =&amp;gt; {
                console.error(`Error fetching details for line item ${item.id}:`, err.message);
                return null; // Return null or handle as appropriate for your needs
            });
        });
        
        // Resolve all promises to get details of each line item
        Promise.all(lineItemPromises).then(lineItemDetails =&amp;gt; {
            console.log(lineItemDetails); // Log the details of all line items
            
            // Further processing can be done here with lineItemDetails
            // For example, filtering high-value line items, aggregating data, etc.
            
            callback({}); // Complete the function
        }).catch(err =&amp;gt; {
            console.error('Error processing line items:', err.message);
            callback({}); // Complete the function, consider passing error details
        });

    }).catch(err =&amp;gt; {
        console.error('Error fetching line item associations:', err.message);
        callback({}); // Complete the function, consider passing error details
    });
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Jan 2024 00:28:49 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/Data-Hub/Custom-Coded-Workflow-find-line-item-associations/m-p/901055#M2003</guid>
      <dc:creator>AOber</dc:creator>
      <dc:date>2024-01-05T00:28:49Z</dc:date>
    </item>
    <item>
      <title>Re: Custom Coded Workflow - find line item associations</title>
      <link>https://community.hubspot.com/t5/Data-Hub/Custom-Coded-Workflow-find-line-item-associations/m-p/902124#M2006</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/687369"&gt;@AOber&lt;/a&gt;&amp;nbsp;and Happy New Year!!!&lt;BR /&gt;&lt;BR /&gt;Thank you for reaching out to the Community!&lt;BR /&gt;&lt;BR /&gt;For information, I'd like to share this documentation on the subject "&lt;A href="https://developers.hubspot.com/docs/api/workflows/custom-code-actions" target="_blank" rel="noopener"&gt;Custom code workflow actions&lt;/A&gt;".&lt;BR /&gt;&lt;BR /&gt;I understand that you are trying to find line item associations via a custom coded workflow action. If that's not the case, please let me know.&lt;BR /&gt;&lt;BR /&gt;I'll be glad to put you in touch with some of our Community Members and some of our Top Experts on this matter:&lt;BR /&gt;&lt;BR /&gt;Hi&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/583096"&gt;@AKoprivec3&lt;/a&gt;,&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/539078"&gt;@MatthiasKunz&lt;/a&gt;,&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/161963"&gt;@JStenbaek&lt;/a&gt;,&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/20261"&gt;@louischausse&lt;/a&gt;,&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/135859"&gt;@Sylg&lt;/a&gt; and,&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/138846"&gt;@kierana&lt;/a&gt; do you have suggestions to help&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/687369"&gt;@AOber&lt;/a&gt;, please?&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;Also, if anybody else has anything to add and/or share, please feel free to join in the conversation :&lt;/STRONG&gt;)&lt;BR /&gt;&lt;BR /&gt;Thank you so much and have a fantastic day!&lt;BR /&gt;&lt;BR /&gt;Best,&lt;BR /&gt;Bérangère&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Jan 2024 09:53:47 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/Data-Hub/Custom-Coded-Workflow-find-line-item-associations/m-p/902124#M2006</guid>
      <dc:creator>BérangèreL</dc:creator>
      <dc:date>2024-01-08T09:53:47Z</dc:date>
    </item>
    <item>
      <title>Re: Custom Coded Workflow - find line item associations</title>
      <link>https://community.hubspot.com/t5/Data-Hub/Custom-Coded-Workflow-find-line-item-associations/m-p/902126#M2007</link>
      <description>&lt;P&gt;Hey&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/230185"&gt;@BérangèreL&lt;/a&gt;&amp;nbsp;&amp;amp;&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/687369"&gt;@AOber&lt;/a&gt;&amp;nbsp; thanks for the mention (hopped on another acc),&lt;BR /&gt;&lt;BR /&gt;There a couple of potential issues I see here but I'd be great if I could see the error you're having when testing this.&lt;BR /&gt;&lt;BR /&gt;Also I'm guessing this is a deal based workflow since you're using the event's object objectId as the dealId correct?&lt;BR /&gt;&lt;BR /&gt;I don't like the associations API too much (its arguably better though) so I usualy use the Deal API if I'm trying to get associated Line Items from the deal and then batch read the IDs of the Line items to get their details.&lt;BR /&gt;&lt;BR /&gt;When I'll see you're error logs I might be able to help you better here.&lt;BR /&gt;&lt;BR /&gt;Best,&lt;BR /&gt;Anze&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Jan 2024 10:01:49 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/Data-Hub/Custom-Coded-Workflow-find-line-item-associations/m-p/902126#M2007</guid>
      <dc:creator>AnzeKoprivec</dc:creator>
      <dc:date>2024-01-08T10:01:49Z</dc:date>
    </item>
  </channel>
</rss>

