Hello. My company just purchased Ops hub pro and I’m taking advantage of the custom code actions in the workflows to create an association between a Company and a custom object. Unfortunately I’m not to advanced at JS as you can see from the code below. I’m attempting to pull in two properties from the Company object (Company ID (hs_object_id( and a custom Company property (china_company_id) to use in the code. When I test the code it threw some undefined errors, ":“Runtime.UserCodeSyntaxError”. I assume its from the variables for those two properties I’m bring in.
Any feedback would be helpful. Thanks in advance.
const hubspot = require(‘@hubspot/api-client’);
const hubspotClient = new hubspot.Client({
apiKey: process.env.HAPIKEY
});
const companyId = event.inputFields[hs_object_id];
const toObjectType = 2-3852312; //custom object id
const toObjectId = event.inputFields[china_company_id];
const associationType = 20; //association id
try {
const apiResponse = await hubspotClient.crm.companies.associationsApi.create(companyId, toObjectType, toObjectId, associationType);
console.log(JSON.stringify(apiResponse.body, null, 2));
} catch (e) {
e.message === ‘HTTP request failed’
? console.error(JSON.stringify(e.response, null, 2))
: console.error(e)
}