⚙ Operations Hub

CWhite36
Member

problems with custom code not updating data output

SOLVE

im using some code to check all contact email addresses within hubspot for their dmarc status to inform those contacts to improve their cyber security.

 

const dns = require('dns').promises;

exports.main = async (event, callback) => {
const email = event.inputFields['email'];
console.log('Email received:', email);

let dmarcResult = 'Invalid or missing email';
let checkedDate = new Date().toISOString().split('T')[0]; // Format: YYYY-MM-DD

if (email && email.includes('@')) {
const domain = email.split('@')[1];
console.log('Domain extracted:', domain);

try {
const records = await dns.resolveTxt(`_dmarc.${domain}`);
if (records.length > 0) {
dmarcResult = records.map(r => r.join('')).join('\n');
} else {
dmarcResult = `No DMARC record found for ${domain}`;
}
} catch (error) {
dmarcResult = `DNS lookup failed for ${domain}`;
console.log('DNS error:', error.message);
}
}

console.log('DMARC result:', dmarcResult);
console.log('Checked date:', checkedDate);

callback({
outputFields: {
dmarc_status_2: dmarcResult,
dmarc_last_checked: checkedDate
}
});
};

 

it doesnt seem to be mapping to the 2 data outputs i have created - dmarc_status_2: dmarcResult (as a string) and  dmarc_last_checked (as a date) 

 

Any ideas?

0 Upvotes
1 Accepted solution
RubenBurdin
Solution
Top Contributor

problems with custom code not updating data output

SOLVE

@CWhite36 Nice work

At this point the missing link is how those outputs get written back to the contact record. In HubSpot, a custom‑code action doesn’t automatically push its output into the CRM; the values just become tokens you can use in later workflow steps.

Quick fix:

  1. Right after the custom‑code action, add a “Set property value” (or “Copy property value”) step.

  2. Choose the contact property you want to update—dmarc_status_2—and in the right‑side token list pick the output token with the same name. Do the same for dmarc_last_checked (use the datetime token from the code step).

  3. Save and re‑enroll a contact. You should see the fields populate a few seconds after the workflow fires.

If you’d rather handle it all inside the code, you can use the HubSpot Client to do an update on the contact right before callback(), but the extra “Set property” step keeps the code simpler and is easier to maintain.

Double‑check the internal names (looks like you’ve got them right), then re‑run the workflow on a test contact and the values should show up in the CRM.

Ping back if it’s still blank—we’ll dig deeper.

 

RubenB_0-1745338477063.png

Ruben Burdin 

Real-Time Data Sync Between any CRM or Database | Founder @Stacksync (YC W24) 

Did my answer help? Please mark it as a solution to help others find it too.

Ruben Burdin Ruben Burdin
HubSpot Advisor
Founder @ Stacksync
Real-Time Data Sync between any CRM and Database
Stacksync Banner

View solution in original post

0 Upvotes
4 Replies 4
CWhite36
Member

problems with custom code not updating data output

SOLVE

Ruben,

 

Many thanks for the solution, this has now been fixed and all working smoothly.

 

Thank you again for the help.

 

Chris

0 Upvotes
RubenBurdin
Top Contributor

problems with custom code not updating data output

SOLVE

@CWhite36 this one’s tricky because everything in your code actually looks fine at a glance, but the issue likely isn’t in your logic — it’s probably in the way the custom code action is configured inside your workflow.

Here’s what I’d check:

  1. Make sure the output field keys exactly match the internal property names — in HubSpot, the property names are not always the same as the label you see in the UI. Double-check that your property internal names are truly dmarc_status_2 and dmarc_last_checked. One small mismatch and HubSpot will just silently ignore the output.

  2. Confirm your output fields are mapped in the workflow step — in the custom code action, you need to manually define the output fields in the right-side panel of the workflow editor. If those aren’t declared and saved there, HubSpot won’t accept the values you're sending back with callback({ outputFields }).

  3. Watch for return timing or async behavior issues — unlikely in your code since you’re using await properly and calling callback() only once, but if there’s any unhandled exception before callback() runs, HubSpot will treat the step as incomplete and not map the fields. You could throw a try/catch around the entire function just to be safe.

  4. Check field types — if dmarc_last_checked is a date property, HubSpot expects it in UNIX timestamp (milliseconds), not ISO string. So you’d want to do:

 

const checkedDate = new Date().getTime(); // returns UNIX ms timestamp

 

Let me know if it’s still not working after that — I can help debug the workflow side too if you send a screenshot of the setup.

Hope this helps.

 

RubenB_0-1745287513359.png

Ruben Burdin 

Real-Time Data Sync Between any CRM or Database | Founder @Stacksync (YC W24) 

Did my answer help? Please mark it as a solution to help others find it too.

Ruben Burdin Ruben Burdin
HubSpot Advisor
Founder @ Stacksync
Real-Time Data Sync between any CRM and Database
Stacksync Banner
0 Upvotes
CWhite36
Member

problems with custom code not updating data output

SOLVE

Thank you RubenB

 

I have updated the unix timestamp code.  This is the workflow, not long at all.

 

CWhite36_0-1745314393897.png

CWhite36_1-1745314466309.png

CWhite36_2-1745314482032.png

I have run a test on an existing contact which appears succesful

CWhite36_3-1745314567489.png

I then checked the tested contact and data hasnt been populated in the fields in the crm.

0 Upvotes
RubenBurdin
Solution
Top Contributor

problems with custom code not updating data output

SOLVE

@CWhite36 Nice work

At this point the missing link is how those outputs get written back to the contact record. In HubSpot, a custom‑code action doesn’t automatically push its output into the CRM; the values just become tokens you can use in later workflow steps.

Quick fix:

  1. Right after the custom‑code action, add a “Set property value” (or “Copy property value”) step.

  2. Choose the contact property you want to update—dmarc_status_2—and in the right‑side token list pick the output token with the same name. Do the same for dmarc_last_checked (use the datetime token from the code step).

  3. Save and re‑enroll a contact. You should see the fields populate a few seconds after the workflow fires.

If you’d rather handle it all inside the code, you can use the HubSpot Client to do an update on the contact right before callback(), but the extra “Set property” step keeps the code simpler and is easier to maintain.

Double‑check the internal names (looks like you’ve got them right), then re‑run the workflow on a test contact and the values should show up in the CRM.

Ping back if it’s still blank—we’ll dig deeper.

 

RubenB_0-1745338477063.png

Ruben Burdin 

Real-Time Data Sync Between any CRM or Database | Founder @Stacksync (YC W24) 

Did my answer help? Please mark it as a solution to help others find it too.

Ruben Burdin Ruben Burdin
HubSpot Advisor
Founder @ Stacksync
Real-Time Data Sync between any CRM and Database
Stacksync Banner
0 Upvotes