Data Hub

BVowles
Member

Custom code block output not working

SOLVE

Hi there HubSpot community. I'm new to Data Hub and hoping someone can help with an issue we're having.

 

We have a custom code block that when it runs it should:

  • take the deal ID of the enrolled deal
  • look to see what deals are associated with the enrolled deal (they'll only be one)
  • return the deal ID of the associated deal as a data output; parentDealId

However, when ever the code block runs the out put always returns this error message:

'Not defined in code'.

 

Below is the code we're using and a screenshot of the setup and the results output. Thank you for your help!

 

exports.main = async (event, callback) => {
const dealId = String(event.inputFields.hs_object_id || '');
const TOKEN = process.env.Account_API_Key;

if (!dealId || !TOKEN) return callback({ parentDealId: '' });

try {
const url = `https://api.hubapi.com/crm/v4/objects/deals/${dealId}/associations/deal`;
const res = await fetch(url, {
method: 'GET',
headers: { Authorization: `Bearer ${TOKEN}`, Accept: 'application/json' }
});

if (!res.ok) return callback({ parentDealId: '' });

const data = await res.json();
const parentDealId = data?.results?.[0]?.toObjectId
? String(data.results[0].toObjectId)
: '';

return callback({ parentDealId });
} catch (e) {
return callback({ parentDealId: '' });
}
};

 

code step 2.pngCode step 1.png

0 Upvotes
1 Accepted solution
BVowles
Solution
Member

Custom code block output not working

SOLVE

I have managed to sort this. The code needed an output field wrapper:

 

return callback({ outputFields: { parentDealId } });

View solution in original post

0 Upvotes
2 Replies 2
Jaycee_Lewis
Community Manager
Community Manager

Custom code block output not working

SOLVE

Hey, @BVowles 👋 Were you able to make any progress here? — Jaycee





loop


Loop Marketing is a new four-stage approach that combines AI efficiency and human authenticity to drive growth.

Learn More




0 Upvotes
BVowles
Solution
Member

Custom code block output not working

SOLVE

I have managed to sort this. The code needed an output field wrapper:

 

return callback({ outputFields: { parentDealId } });

0 Upvotes