<?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 Re: update a deal property based on line-item productid - custom code within a HubSpot workflow in Data Hub</title>
    <link>https://community.hubspot.com/t5/Data-Hub/update-a-deal-property-based-on-line-item-productid-custom-code/m-p/794291#M1497</link>
    <description>&lt;P&gt;Solution&lt;SPAN&gt;&amp;nbsp;-&amp;nbsp;&lt;/SPAN&gt;&lt;A href="https://hubspotdev.slack.com/archives/C019VT42R8X/p1683890995731059" target="_blank" rel="noopener nofollow noreferrer"&gt;https://hubspotdev.slack.com/archives/C019VT42R8X/p1683890995731059&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 16 May 2023 11:36:20 GMT</pubDate>
    <dc:creator>SWM</dc:creator>
    <dc:date>2023-05-16T11:36:20Z</dc:date>
    <item>
      <title>update a deal property based on line-item productid - custom code within a HubSpot workflow</title>
      <link>https://community.hubspot.com/t5/Data-Hub/update-a-deal-property-based-on-line-item-productid-custom-code/m-p/793098#M1483</link>
      <description>&lt;P&gt;&lt;STRONG&gt;Hello Everyone,&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I am developing a Custom code that is designed to retrieve line items associated with a deal and based on certain conditions of line-item, update a specific property of the deal with an incremental value.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;const hubspot = require('@hubspot/api-client');

exports.main = async (event, callback) =&amp;gt; {
  const hubspotClient = new hubspot.Client({
    accessToken: process.env.SECRET_NAME
  });

  const dealId = event.object.objectId; console.log(dealId);

  try {
    const lineItemsResponse = await hubspotClient.crm.deals.associationsApi.getAll(dealId, 'line_item'); 
    const lineItems = lineItemsResponse.results; console.log(lineItems);

    let increaseBy = 0;

    for (const lineItem of lineItems) {
      const productId = lineItem.productId; console.log(productId);

      if (productId === "2032483348") {
        increaseBy = 27;
      } else if (productId === "2032483347") {
        increaseBy = 20;
      } else if (productId === "2032483346") {
        increaseBy = 15;
      } else if (productId === "2032203285") {
        increaseBy = 10;
      } else if (productId === "2032483344") {
        increaseBy = 5;
      }

      const dealResponse = await hubspotClient.crm.deals.basicApi.getById(dealId);
      const deal = dealResponse.body;

      if (deal &amp;amp;&amp;amp; deal.properties) {
        const IncreaseValue = deal.properties.increase_value || 0;
        const dealUpdateRequest = {
          properties: {
            increase_value: IncreaseValue + increaseBy
          }
        };

        await hubspotClient.crm.deals.basicApi.update(dealId, dealUpdateRequest);
      }
    }

    callback({});
  } catch (err) {
    console.error(err);
    throw err;
  }
};&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I am able to get a list of associated Line items, but not the details of the line item (name, ProductID etc), Please let me know if you have any solutions.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image.png" style="width: 400px;"&gt;&lt;img src="https://community.hubspot.com/t5/image/serverpage/image-id/90838i2C45F3EEC32AE38D/image-size/medium?v=v2&amp;amp;px=400" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;</description>
      <pubDate>Fri, 12 May 2023 11:53:24 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/Data-Hub/update-a-deal-property-based-on-line-item-productid-custom-code/m-p/793098#M1483</guid>
      <dc:creator>SWM</dc:creator>
      <dc:date>2023-05-12T11:53:24Z</dc:date>
    </item>
    <item>
      <title>Re: update a deal property based on line-item productid - custom code within a HubSpot workflow</title>
      <link>https://community.hubspot.com/t5/Data-Hub/update-a-deal-property-based-on-line-item-productid-custom-code/m-p/793769#M1489</link>
      <description>&lt;P&gt;Hi &lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/502539"&gt;@SWM&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you for reaching out to the Community!&lt;/P&gt;
&lt;P&gt;I wanted to invite a couple of subject matter experts to this thread to see if they have any advice:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/66301"&gt;@Bryantworks&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/241684"&gt;@ChrisoKlepke&lt;/a&gt;, do you have any tips for&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/502539"&gt;@SWM&lt;/a&gt;?&lt;/P&gt;
&lt;P&gt;Thank you!&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best,&lt;/P&gt;
&lt;P&gt;Kristen&lt;/P&gt;</description>
      <pubDate>Mon, 15 May 2023 12:29:34 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/Data-Hub/update-a-deal-property-based-on-line-item-productid-custom-code/m-p/793769#M1489</guid>
      <dc:creator>kvlschaefer</dc:creator>
      <dc:date>2023-05-15T12:29:34Z</dc:date>
    </item>
    <item>
      <title>Re: update a deal property based on line-item productid - custom code within a HubSpot workflow</title>
      <link>https://community.hubspot.com/t5/Data-Hub/update-a-deal-property-based-on-line-item-productid-custom-code/m-p/793793#M1490</link>
      <description>&lt;P&gt;Hey&lt;BR /&gt;&lt;BR /&gt;Didn't try the following but this should work:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;Replace:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt; const productId = lineItem.productId; console.log(productId);&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;By:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt; const productId = lineItem.toObjectId; console.log(productId);&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;productId is not an attribute of lineItems&lt;BR /&gt;&lt;BR /&gt;Don't forget to mark my reply as a solution if you are satisfied. If not, do not hesitate to ask me anything!&lt;/P&gt;</description>
      <pubDate>Mon, 15 May 2023 12:54:41 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/Data-Hub/update-a-deal-property-based-on-line-item-productid-custom-code/m-p/793793#M1490</guid>
      <dc:creator>louischausse</dc:creator>
      <dc:date>2023-05-15T12:54:41Z</dc:date>
    </item>
    <item>
      <title>Re: update a deal property based on line-item productid - custom code within a HubSpot workflow</title>
      <link>https://community.hubspot.com/t5/Data-Hub/update-a-deal-property-based-on-line-item-productid-custom-code/m-p/794288#M1495</link>
      <description>&lt;P&gt;Hi Louis, Thank you for the suggestions, I found a solution that&amp;nbsp;worked for me.&lt;BR /&gt;Ref -&amp;nbsp;&lt;A href="https://hubspotdev.slack.com/archives/C019VT42R8X/p1683890995731059" target="_blank" rel="noopener"&gt;https://hubspotdev.slack.com/archives/C019VT42R8X/p1683890995731059&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 16 May 2023 11:32:52 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/Data-Hub/update-a-deal-property-based-on-line-item-productid-custom-code/m-p/794288#M1495</guid>
      <dc:creator>SWM</dc:creator>
      <dc:date>2023-05-16T11:32:52Z</dc:date>
    </item>
    <item>
      <title>Re: update a deal property based on line-item productid - custom code within a HubSpot workflow</title>
      <link>https://community.hubspot.com/t5/Data-Hub/update-a-deal-property-based-on-line-item-productid-custom-code/m-p/794290#M1496</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Hi &lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/106905"&gt;@kvlschaefer&lt;/a&gt;, Thank you for considering this.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Meanwhile, I found a solution that&amp;nbsp;worked for me.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Ref -&amp;nbsp;&lt;/SPAN&gt;&lt;A href="https://hubspotdev.slack.com/archives/C019VT42R8X/p1683890995731059" target="_blank" rel="noopener nofollow noreferrer"&gt;https://hubspotdev.slack.com/archives/C019VT42R8X/p1683890995731059&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 16 May 2023 11:34:46 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/Data-Hub/update-a-deal-property-based-on-line-item-productid-custom-code/m-p/794290#M1496</guid>
      <dc:creator>SWM</dc:creator>
      <dc:date>2023-05-16T11:34:46Z</dc:date>
    </item>
    <item>
      <title>Re: update a deal property based on line-item productid - custom code within a HubSpot workflow</title>
      <link>https://community.hubspot.com/t5/Data-Hub/update-a-deal-property-based-on-line-item-productid-custom-code/m-p/794291#M1497</link>
      <description>&lt;P&gt;Solution&lt;SPAN&gt;&amp;nbsp;-&amp;nbsp;&lt;/SPAN&gt;&lt;A href="https://hubspotdev.slack.com/archives/C019VT42R8X/p1683890995731059" target="_blank" rel="noopener nofollow noreferrer"&gt;https://hubspotdev.slack.com/archives/C019VT42R8X/p1683890995731059&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 16 May 2023 11:36:20 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/Data-Hub/update-a-deal-property-based-on-line-item-productid-custom-code/m-p/794291#M1497</guid>
      <dc:creator>SWM</dc:creator>
      <dc:date>2023-05-16T11:36:20Z</dc:date>
    </item>
  </channel>
</rss>

