<?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: Custom code workflow is created double records in &amp;#128172 RevOps Discussions</title>
    <link>https://community.hubspot.com/t5/128172-RevOps-Discussions/Custom-code-workflow-is-created-double-records/m-p/1018632#M2573</link>
    <description>&lt;P&gt;Sure, here it is!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;//Import required libraries &amp;amp; Hubspot functions
const hubspot = require('@hubspot/api-client');

exports.main = async (event, callback) =&amp;gt; { 

//Create a new HubSpot Client session to make the API call
const hubspotClient = new hubspot.Client({
accessToken: process.env.HUBSPOTAPIKEY
});

// Get primary company of the deal
const AssociatedPrimaryCompany = await hubspotClient.crm.associations.v4.basicApi.getPage('deal', event.object.objectId, 'company')
.then(AssociatedPrimaryCompany =&amp;gt; {
const el = AssociatedPrimaryCompany.results.find(({ associationTypes }) =&amp;gt; associationTypes.find(({ label }) =&amp;gt; label === 'Primary')) 
if (el) {
return el.toObjectId;
} else {
console.log('Primary company not found', AssociatedPrimaryCompany.results)
        }
});


// Retrieve data for deal to renew
const distribution_channel = event.inputFields['centrale_d_achat'];
const pb_client_id = event.inputFields['pb_client_id'];
const deal_owner = event.inputFields['hubspot_owner_id'];
const facility_type = event.inputFields['facility_type'];
const sales_specialist_owner = event.inputFields['sales_specialist_owner'];
const cs_owner = event.inputFields['cs_owner'];
const account_manager = event.inputFields['account_manager'];
const ids_hublo = event.inputFields['insitution_id_medgo'];
const ids_mstaff = event.inputFields['id_mstaff'];
const last_billed_date = Number(event.inputFields['last_billed_date']);
const hublo_product = event.inputFields['hublo_product'];
const renewal_ownership = event.inputFields['renewal_ownership'];
const country = event.inputFields['country'];
const beds = event.inputFields['beds'];
const logiciel_de_gestion_des_temps = event.inputFields['logiciel_de_gestion_des_temps'];
const first_day_billed = Number(event.inputFields['billing_start_date']);
const cb_external_id = event.inputFields['cb_external_id'];
// Calculate other data needed
const new_renewal_date = new Date(last_billed_date)
new_renewal_date.setFullYear(new_renewal_date.getFullYear() + 1)
const new_first_day_billed = new Date(first_day_billed)
new_first_day_billed.setFullYear(new_first_day_billed.getFullYear() + 1)
const company_name =  await hubspotClient.crm.companies.basicApi.getById(AssociatedPrimaryCompany, ['name']);
const deal_name = "Renewal " + new_renewal_date.getFullYear() + " - "+ company_name.properties.name + " - " + hublo_product
 
// Create renewal deal properties
const properties = {
"dealname": deal_name,
"closedate": last_billed_date.valueOf(),
"billing_start_date": new_first_day_billed.valueOf(),
"last_billed_date": new_renewal_date.valueOf(),
"hubspot_owner_id": deal_owner,
"pipeline": 32159864,
"dealstage": 204036709,
"insitution_id_medgo": ids_hublo,
"centrale_d_achat": distribution_channel,
"renewal_deal_id" : event.object.objectId,
"pb_client_id" : pb_client_id,
"facility_type" : facility_type,
"sales_specialist_owner" : sales_specialist_owner,
"cs_owner" : cs_owner,
"account_manager" : account_manager,
"ids_mstaff" : ids_mstaff,
"hublo_product" : hublo_product,
"renewal_ownership" : renewal_ownership,
"country" : country,
"beds" : beds,
"logiciel_de_gestion_des_temps" : logiciel_de_gestion_des_temps,
"dealtype" : 'Renewal',
"cb_external_id" : cb_external_id,
};
// Create the deal
const NewDealID = await hubspotClient.crm.deals.basicApi.create({ properties })
.then(DealCreateResponse =&amp;gt; {
return (DealCreateResponse.id);
});

// Get line items associated to the deal
const associatedLineItems = await hubspotClient.crm.associations.v4.basicApi.getPage('deal', event.object.objectId, 'line_items')
.then(associatedLineItems =&amp;gt; {
return associatedLineItems.results.map(({ toObjectId }) =&amp;gt; String(toObjectId))
});  

var inputs = await Promise.all(associatedLineItems.map(async (lineItemId) =&amp;gt; {
const lineItemResponse = await hubspotClient.crm.lineItems.basicApi.getById(lineItemId, [
'quantity',
'discount',
'price',
'hs_product_id',
'recurringbillingfrequency',
'hublo_item',
'is_pool_included',
'is_contract_add_on_included',
'contract_add_on_price',
'hs_recurring_billing_period',
'hs_sku',
'cb_item_id',
'cb_item_family_id',
'cb_discount_frequency',
'cb_item_type',
'cb_site_name',
'cb_subscription_type',
'cb_billing_cycles',
'hs_recurring_billing_start_date',
'type_of_revenue'
]);
      
if (lineItemResponse.properties.hs_recurring_billing_start_date != null) {
var bsd = new Date(lineItemResponse.properties.hs_recurring_billing_start_date)
bsd.setFullYear(bsd.getFullYear() + 1)
lineItemResponse.properties.hs_recurring_billing_start_date = bsd
        }
      
lineItemResponse.properties.type_of_revenue = 'renew'

const properties = lineItemResponse.properties;
// Exclude properties not needed for the clone or that should not be copied
['createdate', 'hs_lastmodifieddate', 'hs_object_id'].forEach(prop =&amp;gt; delete properties[prop]);
console.log(properties)
      
const associations = [{
to: { id: NewDealID },
types: [
{
associationCategory: "HUBSPOT_DEFINED",
associationTypeId: 20,
},
],
}];
return { 
properties,
associations
};
}));
await hubspotClient.crm.lineItems.batchApi.create({ inputs });

// Get all associated companies

const AssociatedCompanies = await hubspotClient.crm.associations.v4.basicApi.getPage('deal', event.object.objectId, 'companies')
.then(AssociatedCompaniesResponse =&amp;gt; {
return AssociatedCompaniesResponse.results.map(({ toObjectId }) =&amp;gt; String(toObjectId))
}); 

// Write companies associations to renewal deal including primary one
var inputs = AssociatedCompanies.map(id =&amp;gt; { 
let relationship;
if (id == AssociatedPrimaryCompany) {
relationship = 'deal_to_company';
} else {
relationship = 'deal_to_company_unlabeled';
}
return {
_from: { id: NewDealID },
to: { id },
type: relationship 
}
})
const BatchInputPublicAssociationCompanies = { inputs };
await hubspotClient.crm.associations.batchApi.create("Deals", "Companies", BatchInputPublicAssociationCompanies);
// Get contacts associations
const AssociatedContacts = await hubspotClient.crm.associations.v4.basicApi.getPage('deal', event.object.objectId, 'contact')
.then(AssociatedContactsResponse =&amp;gt; {
return AssociatedContactsResponse.results.map(({ toObjectId }) =&amp;gt; String(toObjectId))
});  

// Write contact associations to renewal deal
var inputs = AssociatedContacts.map(id =&amp;gt; ({
_from: { id: NewDealID }, // please note the _ before 'from'!!!
to: { id },
type: 'deal_to_contact'
}))
const BatchInputPublicAssociationContacts = { inputs };
await hubspotClient.crm.associations.batchApi.create("Deals", "Contacts", BatchInputPublicAssociationContacts);
 
// Pass information back as a data output to use as a data input with Copy to Property workflow action.
callback({ 
outputFields: {
NewDealID: NewDealID,
}
});
}&lt;/LI-CODE&gt;</description>
    <pubDate>Tue, 30 Jul 2024 10:12:29 GMT</pubDate>
    <dc:creator>AFayet</dc:creator>
    <dc:date>2024-07-30T10:12:29Z</dc:date>
    <item>
      <title>Custom code workflow is created double records</title>
      <link>https://community.hubspot.com/t5/128172-RevOps-Discussions/Custom-code-workflow-is-created-double-records/m-p/1017948#M2568</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Hello,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm requesting your help because Hubspot support team can't help me on that.&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm testing a new workflow&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;to automate the deal renewal, with copied properties &amp;amp; line items, using custom code with Operations Hub.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;When I run tests and enroll the workflow, I have some deals that are randomly created twice.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I investigated a little and when we look at the logs&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture d’écran 2024-07-29 à 10.54.53.png" style="width: 400px;"&gt;&lt;img src="https://community.hubspot.com/t5/image/serverpage/image-id/123429iA755361BAFF77C6C/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Capture d’écran 2024-07-29 à 10.54.53.png" alt="Capture d’écran 2024-07-29 à 10.54.53.png" /&gt;&lt;/span&gt;&lt;SPAN&gt;, the column Action is filled in with "custom code" that has been created, while it doesn't appear on others. And we also there in these doubles that we have “return value” and “logs” information that doesn't appear in the other deals details.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I really don't understand where that comes from and why deals are randomly created in double (because there is no link in terms of property value used in all doublons). I ran the tests last week as well and other doublons were created, not always on the same base deals.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for your help!&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Best,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Annabelle&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 29 Jul 2024 08:56:16 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/128172-RevOps-Discussions/Custom-code-workflow-is-created-double-records/m-p/1017948#M2568</guid>
      <dc:creator>AFayet</dc:creator>
      <dc:date>2024-07-29T08:56:16Z</dc:date>
    </item>
    <item>
      <title>Re: Custom code workflow is created double records</title>
      <link>https://community.hubspot.com/t5/128172-RevOps-Discussions/Custom-code-workflow-is-created-double-records/m-p/1018404#M2569</link>
      <description>&lt;P&gt;Hey &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/738531"&gt;@AFayet&lt;/a&gt;&lt;/SPAN&gt;, thank you for posting in our Community!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It sounds like the custom code in your workflow might be causing the duplicate deal creation. This could be due to the code running multiple times or a logic error. From the logs you shared, it seems the "custom code" action might be executing more than once. Review your custom code for any loops or conditions that could cause this, and check that the workflow isn't being triggered multiple times for the same deal. If you still encounter issues, please share any additional details, and I'll be happy to take a closer look.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Kindly,&lt;/P&gt;
&lt;P&gt;Pam&lt;/P&gt;</description>
      <pubDate>Mon, 29 Jul 2024 22:13:43 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/128172-RevOps-Discussions/Custom-code-workflow-is-created-double-records/m-p/1018404#M2569</guid>
      <dc:creator>PamCotton</dc:creator>
      <dc:date>2024-07-29T22:13:43Z</dc:date>
    </item>
    <item>
      <title>Re: Custom code workflow is created double records</title>
      <link>https://community.hubspot.com/t5/128172-RevOps-Discussions/Custom-code-workflow-is-created-double-records/m-p/1018545#M2570</link>
      <description>&lt;P&gt;Hello Pam,&lt;/P&gt;&lt;P&gt;Thank you for your help!!&lt;/P&gt;&lt;P&gt;Actually the issue is that it's duplicating for some deals but not all of them, so that what made no sense. Is it the same thing for you?&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jul 2024 07:33:10 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/128172-RevOps-Discussions/Custom-code-workflow-is-created-double-records/m-p/1018545#M2570</guid>
      <dc:creator>AFayet</dc:creator>
      <dc:date>2024-07-30T07:33:10Z</dc:date>
    </item>
    <item>
      <title>Re: Custom code workflow is created double records</title>
      <link>https://community.hubspot.com/t5/128172-RevOps-Discussions/Custom-code-workflow-is-created-double-records/m-p/1018588#M2572</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;if could paste in the custom code, i would be glad to take a look at the issue.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jul 2024 08:54:11 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/128172-RevOps-Discussions/Custom-code-workflow-is-created-double-records/m-p/1018588#M2572</guid>
      <dc:creator>sam1989</dc:creator>
      <dc:date>2024-07-30T08:54:11Z</dc:date>
    </item>
    <item>
      <title>Re: Custom code workflow is created double records</title>
      <link>https://community.hubspot.com/t5/128172-RevOps-Discussions/Custom-code-workflow-is-created-double-records/m-p/1018632#M2573</link>
      <description>&lt;P&gt;Sure, here it is!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;//Import required libraries &amp;amp; Hubspot functions
const hubspot = require('@hubspot/api-client');

exports.main = async (event, callback) =&amp;gt; { 

//Create a new HubSpot Client session to make the API call
const hubspotClient = new hubspot.Client({
accessToken: process.env.HUBSPOTAPIKEY
});

// Get primary company of the deal
const AssociatedPrimaryCompany = await hubspotClient.crm.associations.v4.basicApi.getPage('deal', event.object.objectId, 'company')
.then(AssociatedPrimaryCompany =&amp;gt; {
const el = AssociatedPrimaryCompany.results.find(({ associationTypes }) =&amp;gt; associationTypes.find(({ label }) =&amp;gt; label === 'Primary')) 
if (el) {
return el.toObjectId;
} else {
console.log('Primary company not found', AssociatedPrimaryCompany.results)
        }
});


// Retrieve data for deal to renew
const distribution_channel = event.inputFields['centrale_d_achat'];
const pb_client_id = event.inputFields['pb_client_id'];
const deal_owner = event.inputFields['hubspot_owner_id'];
const facility_type = event.inputFields['facility_type'];
const sales_specialist_owner = event.inputFields['sales_specialist_owner'];
const cs_owner = event.inputFields['cs_owner'];
const account_manager = event.inputFields['account_manager'];
const ids_hublo = event.inputFields['insitution_id_medgo'];
const ids_mstaff = event.inputFields['id_mstaff'];
const last_billed_date = Number(event.inputFields['last_billed_date']);
const hublo_product = event.inputFields['hublo_product'];
const renewal_ownership = event.inputFields['renewal_ownership'];
const country = event.inputFields['country'];
const beds = event.inputFields['beds'];
const logiciel_de_gestion_des_temps = event.inputFields['logiciel_de_gestion_des_temps'];
const first_day_billed = Number(event.inputFields['billing_start_date']);
const cb_external_id = event.inputFields['cb_external_id'];
// Calculate other data needed
const new_renewal_date = new Date(last_billed_date)
new_renewal_date.setFullYear(new_renewal_date.getFullYear() + 1)
const new_first_day_billed = new Date(first_day_billed)
new_first_day_billed.setFullYear(new_first_day_billed.getFullYear() + 1)
const company_name =  await hubspotClient.crm.companies.basicApi.getById(AssociatedPrimaryCompany, ['name']);
const deal_name = "Renewal " + new_renewal_date.getFullYear() + " - "+ company_name.properties.name + " - " + hublo_product
 
// Create renewal deal properties
const properties = {
"dealname": deal_name,
"closedate": last_billed_date.valueOf(),
"billing_start_date": new_first_day_billed.valueOf(),
"last_billed_date": new_renewal_date.valueOf(),
"hubspot_owner_id": deal_owner,
"pipeline": 32159864,
"dealstage": 204036709,
"insitution_id_medgo": ids_hublo,
"centrale_d_achat": distribution_channel,
"renewal_deal_id" : event.object.objectId,
"pb_client_id" : pb_client_id,
"facility_type" : facility_type,
"sales_specialist_owner" : sales_specialist_owner,
"cs_owner" : cs_owner,
"account_manager" : account_manager,
"ids_mstaff" : ids_mstaff,
"hublo_product" : hublo_product,
"renewal_ownership" : renewal_ownership,
"country" : country,
"beds" : beds,
"logiciel_de_gestion_des_temps" : logiciel_de_gestion_des_temps,
"dealtype" : 'Renewal',
"cb_external_id" : cb_external_id,
};
// Create the deal
const NewDealID = await hubspotClient.crm.deals.basicApi.create({ properties })
.then(DealCreateResponse =&amp;gt; {
return (DealCreateResponse.id);
});

// Get line items associated to the deal
const associatedLineItems = await hubspotClient.crm.associations.v4.basicApi.getPage('deal', event.object.objectId, 'line_items')
.then(associatedLineItems =&amp;gt; {
return associatedLineItems.results.map(({ toObjectId }) =&amp;gt; String(toObjectId))
});  

var inputs = await Promise.all(associatedLineItems.map(async (lineItemId) =&amp;gt; {
const lineItemResponse = await hubspotClient.crm.lineItems.basicApi.getById(lineItemId, [
'quantity',
'discount',
'price',
'hs_product_id',
'recurringbillingfrequency',
'hublo_item',
'is_pool_included',
'is_contract_add_on_included',
'contract_add_on_price',
'hs_recurring_billing_period',
'hs_sku',
'cb_item_id',
'cb_item_family_id',
'cb_discount_frequency',
'cb_item_type',
'cb_site_name',
'cb_subscription_type',
'cb_billing_cycles',
'hs_recurring_billing_start_date',
'type_of_revenue'
]);
      
if (lineItemResponse.properties.hs_recurring_billing_start_date != null) {
var bsd = new Date(lineItemResponse.properties.hs_recurring_billing_start_date)
bsd.setFullYear(bsd.getFullYear() + 1)
lineItemResponse.properties.hs_recurring_billing_start_date = bsd
        }
      
lineItemResponse.properties.type_of_revenue = 'renew'

const properties = lineItemResponse.properties;
// Exclude properties not needed for the clone or that should not be copied
['createdate', 'hs_lastmodifieddate', 'hs_object_id'].forEach(prop =&amp;gt; delete properties[prop]);
console.log(properties)
      
const associations = [{
to: { id: NewDealID },
types: [
{
associationCategory: "HUBSPOT_DEFINED",
associationTypeId: 20,
},
],
}];
return { 
properties,
associations
};
}));
await hubspotClient.crm.lineItems.batchApi.create({ inputs });

// Get all associated companies

const AssociatedCompanies = await hubspotClient.crm.associations.v4.basicApi.getPage('deal', event.object.objectId, 'companies')
.then(AssociatedCompaniesResponse =&amp;gt; {
return AssociatedCompaniesResponse.results.map(({ toObjectId }) =&amp;gt; String(toObjectId))
}); 

// Write companies associations to renewal deal including primary one
var inputs = AssociatedCompanies.map(id =&amp;gt; { 
let relationship;
if (id == AssociatedPrimaryCompany) {
relationship = 'deal_to_company';
} else {
relationship = 'deal_to_company_unlabeled';
}
return {
_from: { id: NewDealID },
to: { id },
type: relationship 
}
})
const BatchInputPublicAssociationCompanies = { inputs };
await hubspotClient.crm.associations.batchApi.create("Deals", "Companies", BatchInputPublicAssociationCompanies);
// Get contacts associations
const AssociatedContacts = await hubspotClient.crm.associations.v4.basicApi.getPage('deal', event.object.objectId, 'contact')
.then(AssociatedContactsResponse =&amp;gt; {
return AssociatedContactsResponse.results.map(({ toObjectId }) =&amp;gt; String(toObjectId))
});  

// Write contact associations to renewal deal
var inputs = AssociatedContacts.map(id =&amp;gt; ({
_from: { id: NewDealID }, // please note the _ before 'from'!!!
to: { id },
type: 'deal_to_contact'
}))
const BatchInputPublicAssociationContacts = { inputs };
await hubspotClient.crm.associations.batchApi.create("Deals", "Contacts", BatchInputPublicAssociationContacts);
 
// Pass information back as a data output to use as a data input with Copy to Property workflow action.
callback({ 
outputFields: {
NewDealID: NewDealID,
}
});
}&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 30 Jul 2024 10:12:29 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/128172-RevOps-Discussions/Custom-code-workflow-is-created-double-records/m-p/1018632#M2573</guid>
      <dc:creator>AFayet</dc:creator>
      <dc:date>2024-07-30T10:12:29Z</dc:date>
    </item>
    <item>
      <title>Re: Custom code workflow is created double records</title>
      <link>https://community.hubspot.com/t5/128172-RevOps-Discussions/Custom-code-workflow-is-created-double-records/m-p/1019210#M2575</link>
      <description>&lt;P&gt;Hello there, I can't suggest (review) the custom code you're using in your workflow, as I'm not a tech person.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Same time, I would like to say that you can also explore some Apps that do absolutelly same functionality and provides UI, withing what you can do that automatinf of deal re-newal/duplicating.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;We built a CloneNer app (&lt;A href="https://ecosystem.hubspot.com/marketplace/apps/sales/crm/clonener-2156213" target="_blank" rel="noopener"&gt;app link in the HubSpot Marketplace&lt;/A&gt;)&amp;nbsp; users are using that to automate their deals creation.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please let me know if you will have any questions about how to use the app or anything else.&lt;/P&gt;&lt;P&gt;Kind Regards,&lt;/P&gt;&lt;P&gt;John Maret&lt;/P&gt;</description>
      <pubDate>Wed, 31 Jul 2024 05:17:22 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/128172-RevOps-Discussions/Custom-code-workflow-is-created-double-records/m-p/1019210#M2575</guid>
      <dc:creator>JohnMaret</dc:creator>
      <dc:date>2024-07-31T05:17:22Z</dc:date>
    </item>
    <item>
      <title>Re: Custom code workflow is created double records</title>
      <link>https://community.hubspot.com/t5/128172-RevOps-Discussions/Custom-code-workflow-is-created-double-records/m-p/1019528#M2576</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;One solution for preventing duplicate deal creation&amp;nbsp;is to separate the code into two custom code blocks.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the 1st one create the deal and set the deal &lt;STRONG&gt;record_id&lt;/STRONG&gt; as output.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the 2nd custom code block use the 1st custom code output and do other necessary associations.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also other thing to note , its better to use async/await with axios rather than promise&amp;nbsp;to handle API calls,&amp;nbsp; async/await code is mush more tidy.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 31 Jul 2024 16:05:59 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/128172-RevOps-Discussions/Custom-code-workflow-is-created-double-records/m-p/1019528#M2576</guid>
      <dc:creator>sam1989</dc:creator>
      <dc:date>2024-07-31T16:05:59Z</dc:date>
    </item>
  </channel>
</rss>

