# Custom Code not outputting to created string field

**URL:** <https://community.hubspot.com/t/custom-code-not-outputting-to-created-string-field/136005>\
**Category:** CRM\
**Tags:** crm\
**Created:** [July 10, 2025, 5:08pm UTC](https://community.hubspot.com/t/custom-code-not-outputting-to-created-string-field/136005 "2025-07-10T17:08:06Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jerrelle630](https://avatars.discourse-cdn.com/v4/letter/j/b4bc9f/32.png) [@Jerrelle630](https://community.hubspot.com/u/Jerrelle630)\
**Post date:** [July 10, 2025, 5:08pm UTC](https://community.hubspot.com/t/custom-code-not-outputting-to-created-string-field/136005/1 "2025-07-10T17:08:06Z")

</div>

I have a custom code where I want to capture only the “time” of a created date field (set to date and time picker) and place the text into a new property that is set to single-line-text.  
If I use custom mode, I can get the date and time to populate the field, even though it is coded to just return HH:mm  
format\_datetime([createdate], ‘HH:mm’, ‘America/New\_York’, ‘en-US’)  
If I use custom code, the output test properly and display the time correctly, but does not populate the actual field when I enroll a contact:

exports.main = async (event, callback) =\> {  
const dateTime = event.inputFields[‘createdate’];  
let formattedTime = ‘’;

if (dateTime) {  
const timestamp = typeof dateTime === ‘string’ ? parseInt(dateTime) : dateTime;  
const dateObj = new Date(timestamp);  
if (!isNaN(dateObj)) {  
const hours = String(dateObj.getHours()).padStart(2, ‘0’);  
const minutes = String(dateObj.getMinutes()).padStart(2, ‘0’);  
const seconds = String(dateObj.getSeconds()).padStart(2, ‘0’);  
formattedTime = `${hours}:${minutes}:${seconds}`;  
} else {  
console.log(“Invalid Date object from:”, timestamp);  
}  
} else {  
console.log(“createdate is undefined or null”);  
}

console.log(“createdate:”, dateTime);  
console.log(“Formatted time:”, formattedTime);

callback({  
outputFields: {  
time\_only\_field: formattedTime  
}  
});  
};

Any advice would be greatly appeciated. Input and Output matches correctly, as noted when used in custom mode.

---

<div class="post-metadata">

**Author:** ![ArisudanTiwari](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/arisudantiwari/32/93919_2.png) [@ArisudanTiwari](https://community.hubspot.com/u/ArisudanTiwari)\
**Post date:** [July 10, 2025, 6:13pm UTC](https://community.hubspot.com/t/custom-code-not-outputting-to-created-string-field/136005/2 "2025-07-10T18:13:04Z")

</div>

Hi @Jerrelle630 ,

The most likely issue is with how the createdate timestamp is being interpreted. HubSpot uses timestamps in milliseconds, so be sure your code isn’t treating them as seconds. Also, double-check that the internal name of the output property (time\_only\_field) is correctly mapped in your workflow; even a small mismatch can cause the output to fail silently.

Here’s a refined version of your code with timezone and format handling:

`exports.main = async (event, callback) => {const dateTime = event.inputFields['createdate'];let formattedTime = '';if (dateTime) {const dateObj = new Date(dateTime); // HubSpot timestamp is in msif (!isNaN(dateObj.getTime())) {formattedTime = dateObj.toLocaleTimeString('en-US', {hour12: false,hour: '2-digit',minute: '2-digit',second: '2-digit',timeZone: 'America/New_York',});} else {console.error("Invalid date:", dateTime);}} else {console.error("createdate is null/undefined");}console.log("Formatted time:", formattedTime);callback({outputFields: {time_only_field: formattedTime, // Make sure this matches the internal name},});};`

If it’s still not working, feel free to share a screenshot of your workflow configuration and property settings, and I’d be happy to help troubleshoot further!

---

<div class="post-metadata">

**Author:** ![Jerrelle630](https://avatars.discourse-cdn.com/v4/letter/j/b4bc9f/32.png) [@Jerrelle630](https://community.hubspot.com/u/Jerrelle630)\
**Post date:** [July 10, 2025, 6:24pm UTC](https://community.hubspot.com/t/custom-code-not-outputting-to-created-string-field/136005/3 "2025-07-10T18:24:16Z")

</div>

I took into account the milliseconds which is being interpreted correctly. This is more of an issue with the custom code, as the custom mode does provide the date and time. The output string matches in both custom code and custom mode tests as they use the same field in testing.

1. With the custom code, all tests are successful. The milliseconds is interpretted properly. The test out put shows the correct time with no date, but when enrolling live tests, the field does not populates.

2. With custom code, works properly, with one issue; it list the date as well as the time, when we only need the time.

---

<div class="post-metadata">

**Author:** ![Jerrelle630](https://avatars.discourse-cdn.com/v4/letter/j/b4bc9f/32.png) [@Jerrelle630](https://community.hubspot.com/u/Jerrelle630)\
**Post date:** [July 11, 2025, 12:54pm UTC](https://community.hubspot.com/t/custom-code-not-outputting-to-created-string-field/136005/4 "2025-07-11T12:54:44Z")

</div>

Hello @ArisudanTiwari

Thank you for assist. I’m still getting the following error with the test:

```auto
START RequestId: 55ad7bd7-5bd8-4988-8d34-cbcc5a8b3a7e Version: $LATEST
2025-07-11T12:37:47.653Z	ERROR	Invalid date: 1752093026768
2025-07-11T12:37:47.653Z	INFO	Formatted time: 

```

Below is my workflow image:

 ![Jerrelle630_0-1752237654996.png](https://d2qpr2jzcazej7.cloudfront.net/original/3X/d/c/dc6a02b4210170ac639aa6e511c7cfb7e3efb220.png)

![Jerrelle630_1-1752237802606.png](https://d2qpr2jzcazej7.cloudfront.net/original/3X/7/7/773310a3d6721960366a92cc9c9d898efba5a488.png)

 ![Jerrelle630_2-1752237819835.png](https://d2qpr2jzcazej7.cloudfront.net/original/3X/7/0/706b537fd8a94df7b2a82c0507994aaf5f72deeb.png)

Not sure why it partially works with custom mode, but completely errors out with custom code. Please let me know if additional screenshots are needed.

---

<div class="post-metadata">

**Author:** ![Jerrelle630](https://avatars.discourse-cdn.com/v4/letter/j/b4bc9f/32.png) [@Jerrelle630](https://community.hubspot.com/u/Jerrelle630)\
**Post date:** [July 11, 2025, 4:24pm UTC](https://community.hubspot.com/t/custom-code-not-outputting-to-created-string-field/136005/5 "2025-07-11T16:24:48Z")

</div>

@ArisudanTiwari

Thank you for the assistance. I kept expecting the output to write itseld to the property field, however, I added an edit record field to overwrite itself and that did the trick.

 ![Jerrelle630_0-1752251053090.png](https://d2qpr2jzcazej7.cloudfront.net/original/3X/0/2/020b4ebdd0864f25da462290a9dcd90eee88411b.png)
