<?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: Add an association label when associating Contact to Deal with custom-coded workflow actions in Data Hub</title>
    <link>https://community.hubspot.com/t5/Data-Hub/Add-an-association-label-when-associating-Contact-to-Deal-with/m-p/720029#M1138</link>
    <description>&lt;P&gt;Thanks so much! For reference for other users, I used the actual label of the association id ("policyholder") instead of the ID number.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 17 Nov 2022 22:16:18 GMT</pubDate>
    <dc:creator>Hollyce</dc:creator>
    <dc:date>2022-11-17T22:16:18Z</dc:date>
    <item>
      <title>Add an association label when associating Contact to Deal with custom-coded workflow actions</title>
      <link>https://community.hubspot.com/t5/Data-Hub/Add-an-association-label-when-associating-Contact-to-Deal-with/m-p/719461#M1132</link>
      <description>&lt;P&gt;I have a working custom-coded workflow action that finds a Deal with a property value matching the value of the Contact's property. It succesfully associates the Deal with the Contact.&amp;nbsp; I would like to assign an association label as well, but I can't quite get the syntax right.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Here is the successful code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;// Import the Hubspot NodeJS Client Library - this will allow us to use the HubSpot APIs
const hubspot = require('@hubspot/api-client');

/* 
This function is called when the custom code action is executed. It takes 2 arguements. The first is the event object which contains information on the currently enrolled object. 
The second is the callback function which is used to pass data back to the workflow.
*/
exports.main = (event, callback) =&amp;gt; {
  
  // Instantiate a new HubSpot private app (secret)
  const hubspotClient = new hubspot.Client({
    accessToken: process.env.custom_code_private_app
  });
  
  // Retrive the currently enrolled contacts "Policy ID" property
  hubspotClient.crm.contacts.basicApi.getById(event.object.objectId, ["policy_id"])
    .then(results =&amp;gt; {
	// Get data from the results and store in variables
	let policyIdValue = results.body.properties.policy_id;
        //console.log("SEARCH TERM: " + policyIdValue); // - FOR DEBUG

	// Create search criteria   
	const filter = { propertyName: 'policy_id', operator: 'EQ', value: policyIdValue }
	const filterGroup = { filters:	[filter] 	}
        const sort = JSON.stringify({ propertyName: 'policy_id', direction: 'DESCENDING'})
        const properties = ['policy_id']
        const limit = 1
        const after = 0
        
        const searchCriteria = {
          filterGroups: [filterGroup],
          sorts: [sort],
          properties,
          limit,
          after
        }
    
      // Search the CRM for Deals matching "policyID" variable defined earlier
      hubspotClient.crm.deals.searchApi.doSearch(searchCriteria).then(searchDealResponse =&amp;gt; {
        
         //console.log("RESULTS: " + searchDealResponse.body.total); // - FOR DEBUG
 
         // If total equals 0 no results found
         if(searchDealResponse.body.total == 0){ console.log("DEAL WITH Policy ID " + policyIdValue  + "NOT FOUND.") // - FOR DEBUG
           
         }else{ // MATCH FOUND - ASSOCIATE DEAL TO CONTACT
           // console.log("DEAL " + Policy ID + " FOUND: ASSOCIATE RECORDS"); // - FOR DEBUG
          //Associate Deal with Contact
           hubspotClient.crm.deals.associationsApi.create(searchDealResponse.body.results[0].id,'contacts', event.object.objectId,'deal_to_contact');
         }
      });
   
      callback({outputFields: {}});
    
    })
    .catch(err =&amp;gt; {
      console.error(err);
    });
}&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I know I need to use these variables somehow:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;{&lt;/P&gt;
&lt;P&gt;&amp;nbsp;associationCategory: 'USER_DEFINED',&lt;/P&gt;
&lt;P&gt;&amp;nbsp;associationTypeId: 2&lt;/P&gt;
&lt;P&gt;}&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But the examples on the Associations v4 documentation page did not give me the right syntax for custom-coded workflow actions. Can anyone help? Thanks in advance!&lt;/P&gt;</description>
      <pubDate>Wed, 16 Nov 2022 22:00:13 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/Data-Hub/Add-an-association-label-when-associating-Contact-to-Deal-with/m-p/719461#M1132</guid>
      <dc:creator>Hollyce</dc:creator>
      <dc:date>2022-11-16T22:00:13Z</dc:date>
    </item>
    <item>
      <title>Re: Add an association label when associating Contact to Deal with custom-coded workflow actions</title>
      <link>https://community.hubspot.com/t5/Data-Hub/Add-an-association-label-when-associating-Contact-to-Deal-with/m-p/719935#M1137</link>
      <description>&lt;DIV class=""&gt;On this line:&lt;/DIV&gt;&lt;PRE&gt;hubspotClient.crm.deals.associationsApi.create(searchDealResponse.body.results[0].id,'contacts', event.object.objectId,'deal_to_contact');&lt;/PRE&gt;&lt;DIV class=""&gt;Swap deal_to_contact with the association type id of your choice&lt;/DIV&gt;</description>
      <pubDate>Thu, 17 Nov 2022 18:58:44 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/Data-Hub/Add-an-association-label-when-associating-Contact-to-Deal-with/m-p/719935#M1137</guid>
      <dc:creator>CMcKay</dc:creator>
      <dc:date>2022-11-17T18:58:44Z</dc:date>
    </item>
    <item>
      <title>Re: Add an association label when associating Contact to Deal with custom-coded workflow actions</title>
      <link>https://community.hubspot.com/t5/Data-Hub/Add-an-association-label-when-associating-Contact-to-Deal-with/m-p/720029#M1138</link>
      <description>&lt;P&gt;Thanks so much! For reference for other users, I used the actual label of the association id ("policyholder") instead of the ID number.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Nov 2022 22:16:18 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/Data-Hub/Add-an-association-label-when-associating-Contact-to-Deal-with/m-p/720029#M1138</guid>
      <dc:creator>Hollyce</dc:creator>
      <dc:date>2022-11-17T22:16:18Z</dc:date>
    </item>
    <item>
      <title>Re: Add an association label when associating Contact to Deal with custom-coded workflow actions</title>
      <link>https://community.hubspot.com/t5/Data-Hub/Add-an-association-label-when-associating-Contact-to-Deal-with/m-p/749249#M1258</link>
      <description>&lt;P&gt;THANK YOU SO MUCH!&lt;BR /&gt;&lt;BR /&gt;I had the SAME EXACT scenario, literally!!&lt;BR /&gt;For others that stumble this way, &lt;STRONG&gt;USE THE LABEL OF THE ASSOCIATION TYPE&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below is a custom association set in our account.&lt;/P&gt;&lt;P&gt;Using the &lt;STRONG&gt;LABEL&lt;/STRONG&gt; &lt;STRONG&gt;VALUE&lt;/STRONG&gt; worked (&lt;STRONG&gt;Influencer&lt;/STRONG&gt;), despite Hub's code snippet saying to use something completly different. I'd love for Hubspot to fix their code snippet because I'd like to know officially what to use for future instances so this doesn't break down the road.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;{
  "category": "USER_DEFINED",
  "typeId": 7,
  "label": "Influencer"
}&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 31 Jan 2023 06:48:26 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/Data-Hub/Add-an-association-label-when-associating-Contact-to-Deal-with/m-p/749249#M1258</guid>
      <dc:creator>FNeri</dc:creator>
      <dc:date>2023-01-31T06:48:26Z</dc:date>
    </item>
    <item>
      <title>Re: Add an association label when associating Contact to Deal with custom-coded workflow actions</title>
      <link>https://community.hubspot.com/t5/Data-Hub/Add-an-association-label-when-associating-Contact-to-Deal-with/m-p/866764#M1851</link>
      <description>&lt;P&gt;What end point were you using here as the ones I see in the docs only allow for HUBSPOT_DEFINED and "label" doesnt seem to do anything for this guy&amp;nbsp;&lt;A href="https://api.hubapi.com/crm-associations/v1/associations/create-batch" target="_blank"&gt;https://api.hubapi.com/crm-associations/v1/associations/create-batch&lt;/A&gt;. My thanks in advance.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 19 Oct 2023 04:50:22 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/Data-Hub/Add-an-association-label-when-associating-Contact-to-Deal-with/m-p/866764#M1851</guid>
      <dc:creator>KevinWilliams</dc:creator>
      <dc:date>2023-10-19T04:50:22Z</dc:date>
    </item>
  </channel>
</rss>

