⚙ Operations Hub

DouweDeinum
Member | Elite Partner
Member | Elite Partner

Custom coded workflow gives errors with bulk enrollment

Hi,

we prepared a workflow with a custom coded action. When we test the custom code on individual enrolled records, it works perfectly.
But when I turn on the workflow and enroll all records that need to go through the custom code, most of them are skipped because of an error. And the error is very unclear. It shows only:

DouweDeinum_0-1675437090879.png


We have enough API calls to work with, and HubSpot does not say that we hit the limits. So that should not be the case.

Digging deeper does not clarify what the problem is. Has anyone some ideas what could cause the issue? Has anyone a similar experience, an if yes how did yo resolve that?

0 Upvotes
5 Replies 5
louischausse
Key Advisor | Platinum Partner
Key Advisor | Platinum Partner

Custom coded workflow gives errors with bulk enrollment

Can't know for sure without seeing the code and the records you are enrolling but it seems to me that maybe some of the records in the bulk enroll don't have known value for all the required properties set as variable in your code. 


This is why it works with individual test record but when you enroll them all it fails for some.

Don't forget to mark my reply as a solution if you are satisfied. If not, do not hesitate to ask me anything!

Louis Chaussé from Auxilio HubSpot Solutions Partner Signature
Louis Chaussé from Auxilio HubSpot Solutions Partner Meeting link
MiaSrebrnjak
Community Manager
Community Manager

Custom coded workflow gives errors with bulk enrollment

Hi @DouweDeinum,

 

Thank you for reaching out to the Community!

Could you share the custom code you're using? Or at least a part of it? 

 

I'll tag in a couple of subject matter experts though to see if they have any insight on this: 

Hi @miljkovicmisa,  @louischausse@Teun,  have you ever encountered such an error? Thanks! 

 

Cheers
Mia, Community Team


Wusstest du, dass es auch eine DACH-Community gibt?
Nimm an regionalen Unterhaltungen teil, indem du deine Spracheinstellungen änderst


Did you know that the Community is available in other languages?
Join regional conversations by
changing your language settings

0 Upvotes
DouweDeinum
Member | Elite Partner
Member | Elite Partner

Custom coded workflow gives errors with bulk enrollment

We found still a HAPIKEY instruction. Apparently we missed that one. So that is at least an error fixed 😮; And we finally got a hint that points towards the secondly limit.

Thanks for your response, I think we now know what to do.

 

0 Upvotes
DouweDeinum
Member | Elite Partner
Member | Elite Partner

Custom coded workflow gives errors with bulk enrollment

Hi,

see custom code listed here. The goal is to set an association between company and deal based on a property in the deal. This property is always filled.

 

// Get the HubSpot client
const hubspot = require('@hubspot/api-client');
const http = require("https");
const {execSync} = require('child_process');

// Call main function
exports.main = (event, callback) => {
return callback(processEvent(event));};

// Process the work
function processEvent(event) {

// HAPIKEY is defined in secrets at the Workflow / Custom Code
// Instantiate the HS Client

const hubspotClient = new hubspot.Client({
accessToken: process.env.WorkflowCustomCode
});

// Interval
const intMin = 2;
const intMax = 4;

// Get the Deal ID
const dealId = event.object.objectId;

// Declare constants
const fromObjectType = "Deal";
const toObjectType = "companies";
const associationType = "deal_to_company";

// Declare variables
let companyId = 0

// Get the my_store_id property value
// It looks like we need to use the searchApi instead of the basicApi as the custom properties are not returned by the basicApi

const dealProperties = ["order_store_gln"]
const dealFilter = { propertyName: "hs_object_id", operator: "EQ", value: dealId }
let dealFilterGroup = { filters: [dealFilter] }
let dealSearchRequest = { properties: dealProperties, filterGroups: [dealFilterGroup] }
execSync('sleep ' + randomIntFromInterval(intMin, intMax));
hubspotClient.crm.deals.searchApi.doSearch(dealSearchRequest)
.then (dealResults => {
if (dealResults.body.total > 0) {

// We have found the deal
// Let's get the company based on order_store_gln

let storeId = dealResults.body.results[0].properties.order_store_gln;
if (storeId > 0) {
const companyFilter = { propertyName: "storegln", operator: "EQ", value: storeId }
const companyFilterGroup = { filters: [companyFilter] }
const companySearchRequest = { filterGroups: [companyFilterGroup] }
execSync('sleep ' + randomIntFromInterval(intMin, intMax));
hubspotClient.crm.companies.searchApi.doSearch(companySearchRequest)
.then (companyResult => {
if (companyResult.body.total > 0) {
companyId = companyResult.body.results[0].id
if (companyId > 0) {

// We have found the company to associate with
// Let's check if there already is an association with another company; that one should be deleted.

const BatchInputPublicObjectId = { inputs: [{"id":dealId}] };

try {
execSync('sleep ' + randomIntFromInterval(intMin, intMax));
hubspotClient.crm.associations.batchApi.read(fromObjectType, toObjectType, BatchInputPublicObjectId)
.then (assResults => {
if (assResults.body) {
for (let i = 0; i < assResults.body.results.length; i++) {
let assCompanyId = assResults.body.results[i].to[0].id
if (assCompanyId != companyId) {

// Delete the current association

var options = {
"method": "DELETE",
"hostname": "api.hubapi.com",
"port": null,
"path": "/crm/v4/objects/Deal/" + dealId + "/associations/Company/" + assCompanyId + "?hapikey=" + process.env.HAPIKEY,
"headers": {
"accept": "application/json"
}
};
execSync('sleep ' + randomIntFromInterval(intMin, intMax));
var req = http.request(options);
req.end();
}
}
}
})

// We can now create the new association
try {
execSync('sleep ' + randomIntFromInterval(intMin, intMax));
hubspotClient.crm.deals.associationsApi.create(dealId, toObjectType, companyId, associationType)
} catch (e) {
e.message === 'HTTP request failed'
? console.error(JSON.stringify(e.response, null, 2))
: console.error(e)
}

} catch (e) {
e.message === 'HTTP request failed'
? console.error(JSON.stringify(e.response, null, 2))
: console.error(e)
}
}
}
})
}
}
})
}

function randomIntFromInterval(min, max) { // min and max included
return Math.floor(Math.random() * (max - min + 1) + min)
}

0 Upvotes
DouweDeinum
Member | Elite Partner
Member | Elite Partner

Custom coded workflow gives errors with bulk enrollment

We found still a HAPIKEY instruction. Apparently we missed that one. So that is at least an error fixed 😮

0 Upvotes