# Problem: Update Property with Custom Code (Python)

**URL:** <https://community.hubspot.com/t/problem-update-property-with-custom-code-python/84175>\
**Category:** APIs & Integrations\
**Tags:** enterprise\
**Created:** [June 27, 2023, 7:45am UTC](https://community.hubspot.com/t/problem-update-property-with-custom-code-python/84175 "2023-06-27T07:45:54Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![henryt1](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/henryt1/32/3459_2.png) [@henryt1](https://community.hubspot.com/u/henryt1)\
**Post date:** [June 27, 2023, 7:45am UTC](https://community.hubspot.com/t/problem-update-property-with-custom-code-python/84175/1 "2023-06-27T07:45:54Z")

</div>

Hallo Everyone,

thanks for having a look on my problem.

**My goal:** I have a date property and want to increase that date on one day with the help of custom code.

For example: Datefield is 10/08/2023 before the Code and after running the code it’s 10/09/2023 (+ 1 day)

The Code works correctly and gives me the right output.

 ![](https://d2qpr2jzcazej7.cloudfront.net/original/3X/3/f/3f3cb1f3d238674a647ec444286da018828d6ed8.png)

**Problem:** I dont get it to update the property (‘contract\_start\_date’) within the Deal. When I enroll the workflow, the property stays untouched.

My Workflow looks like this:

 ![](https://d2qpr2jzcazej7.cloudfront.net/original/3X/b/f/bf23922c54cf7ea620959bdc44e263cded38e740.png)

What am I doing wrong?

Huge thanks in advance for your help!

**Update:** I get this Workflow error, so maybe something with the code / correct date format is wrong?

 ![Screenshot 2023-06-27 095017.png](https://d2qpr2jzcazej7.cloudfront.net/original/3X/f/7/f77083a1eac3483bbca65dec8b6c99ddfdbf86d0.png)

The Code looks like this:

```lia-code-sample
import os
from hubspot import HubSpot
from hubspot.crm.contacts import ApiException

from datetime import datetime, timedelta

def main(event):
 # Use inputs to get data from any action in your workflow and use it in your code instead of having to use the HubSpot API.
 contract_start_date = event.get("inputFields").get("contract_start_date")

 # Convert timestamp to a datetime-object
 contract_start_date = datetime.fromtimestamp(int(contract_start_date) / 1000)

 # add 1 day to the current date
 new_date = contract_start_date + timedelta(days=1)

 # convert to the right format (MM/DD/YYYY)
 new_date_formatted = new_date.strftime('%m/%d/%Y')

 # Set new date as the value of the date-property
 event['inputFields']['contract_start_date'] = new_date_formatted

 return {
 "outputFields": {
 "contract_start_date": new_date_formatted # Hier verwenden wir den formatierten String
 }
 }

```

---

<div class="post-metadata">

**Author:** ![himanshurauthan](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/himanshurauthan/32/53076_2.png) [@himanshurauthan](https://community.hubspot.com/u/himanshurauthan)\
**Post date:** [June 27, 2023, 8:32am UTC](https://community.hubspot.com/t/problem-update-property-with-custom-code-python/84175/2 "2023-06-27T08:32:00Z")

</div>

Hello @henryt1  
change the code to update the outputFields object instead of the inputFields object. Here is the updated code.

```lia-code-sample
import os
from hubspot import HubSpot
from hubspot.crm.contacts import ApiException

from datetime import datetime, timedelta

def main(event):
 # Use inputs to get data from any action in your workflow and use it in your code instead of having to use the HubSpot API.
 contract_start_date = event.get("inputFields").get("contract_start_date")

 # Convert timestamp to a datetime-object
 contract_start_date = datetime.fromtimestamp(int(contract_start_date) / 1000)

 # add 1 day to the current date
 new_date = contract_start_date + timedelta(days=1)

 # convert to the right format (MM/DD/YYYY)
 new_date_formatted = new_date.strftime('%m/%d/%Y')

 # Set new date as the value of the date-property
 event['outputFields']['contract_start_date'] = new_date_formatted

 return {
 "outputFields": {
 "contract_start_date": new_date_formatted # Hier verwenden wir den formatierten String
 }
 }

```

After updating the code, you should be able to successfully update the contract\_start\_date property in the deal.

---

<div class="post-metadata">

**Author:** ![henryt1](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/henryt1/32/3459_2.png) [@henryt1](https://community.hubspot.com/u/henryt1)\
**Post date:** [June 27, 2023, 9:26am UTC](https://community.hubspot.com/t/problem-update-property-with-custom-code-python/84175/3 "2023-06-27T09:26:51Z")

</div>

Hello Himanshu,

thank you really much for your quick answer! When I update the code, it gives me this error:

 ![](https://d2qpr2jzcazej7.cloudfront.net/original/3X/8/3/832ec7ca6a7a0c559e7cb06309d82f689771d1a0.png)

Is there somethin I could do?

---

<div class="post-metadata">

**Author:** ![henryt1](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/henryt1/32/3459_2.png) [@henryt1](https://community.hubspot.com/u/henryt1)\
**Post date:** [June 27, 2023, 10:57am UTC](https://community.hubspot.com/t/problem-update-property-with-custom-code-python/84175/4 "2023-06-27T10:57:01Z")

</div>

I found the solution: the date-output from my code wasn’t formatted correctly:  
It needed to be in this way: **UTC midnight aligned unix millisecond timestamps (ex: May 16 2022 would be 1652659200000)**

**Here’s my updated Code:**

```lia-code-sample
import os
from hubspot import HubSpot
from hubspot.crm.contacts import ApiException

from datetime import datetime, timedelta

def main(event):
 # Verwende die Eingaben, um Daten aus einer Aktion in deinem Workflow zu erhalten und im Code zu verwenden, anstatt die HubSpot API verwenden zu müssen.
 contract_start_date = event.get("inputFields").get("contract_start_date")

 # Konvertiere den Zeitstempel in ein datetime-Objekt
 contract_start_date = datetime.fromtimestamp(int(contract_start_date) / 1000).date()

 # Addiere 1 Tag zum aktuellen Datum
 new_date = contract_start_date + timedelta(days=1)

 # Konvertiere das neue Datum zurück in das erforderliche Format (UTC midnight aligned Unix millisecond timestamp)
 new_date_formatted = int(new_date.strftime('%s')) * 1000

 # Setze das neue Datum als Wert des Datum-Properties
 event['inputFields']['contract_start_date'] = new_date_formatted

 return {

```
