💬 RevOps Discussions

SKerrigan5
Participante

Update deal close date to future

resolver

I am trying to update a deal close date to a date in the future (e.g. last day of the month) once it has gone past the close date and the deal is still open. This will help in forecasting numbers.

 

We have operations hub and I think this should be possible by using custom code but I can't get it to work. Anyone know how?

0 Me gusta
1 Soluciones aceptada
TSburv
Solución
Participante

Update deal close date to future

resolver

Hello,

 

I'm glad my answer was helpful. Here’s what you might need to check and adjust:

1. Property to include in the code. From your screenshot, it looks like you have the closedate property included. Make sure that this is correctly linked to the deal's close date property. Double-check that the property name exactly matches how it's defined in HubSpot. If needed, use the Add property button to make sure it's properly linked.

 

2. Data outputs. You have a variable called hs_execution_state as one of the outputs. This is typically used to track the execution status of your custom code action. Ensure that you have properly defined and are using this enumeration to track the success or failure of the action. You may want to make sure that your code correctly handles these outputs, especially if you're using a status like Succeeded or Failed.

 

If you're still encountering issues, I’d recommend testing the custom code in smaller parts or logging more details in the action to track the specific flow and see what might be going wrong.

Ver la solución en mensaje original publicado

3 Respuestas 3
TSburv
Participante

Update deal close date to future

resolver

Hi,

 

Try creating a workflow. Go to the automation section, make a new workflow for deals, and set a trigger for when the close date has passed but the deal is still open. Then, add an action to Update deal property and set the new close date.

 

Another option is to use custom code with Operations Hub. Write a script to check and update the close date if needed. Here's an example in Python:

 

from datetime import datetime, timedelta
import hubspot

api_client = hubspot.Client.create()

def update_deal_close_date(deal_id):
new_close_date = (datetime.now() + timedelta(days=(30 - datetime.now().day))).strftime('%Y-%m-%d')
deal_properties = {"closedate": new_close_date}
api_client.crm.deals.basic_api.update(deal_id, properties=deal_properties)

deals = api_client.crm.deals.get_all()
for deal in deals:
if deal.properties['closedate'] < datetime.now().strftime('%Y-%m-%d'):
update_deal_close_date(deal.id)

 

Integrate this code into your custom workflow action.

0 Me gusta
SKerrigan5
Participante

Update deal close date to future

resolver

Thank you so much @TSburv. It's still not updating the close logic, wondering do I need to add / edit the "Property to include in the code" or the "Data outputs"?

SKerrigan5_0-1737639363350.png

 

SKerrigan5_1-1737639373006.png

 

0 Me gusta
TSburv
Solución
Participante

Update deal close date to future

resolver

Hello,

 

I'm glad my answer was helpful. Here’s what you might need to check and adjust:

1. Property to include in the code. From your screenshot, it looks like you have the closedate property included. Make sure that this is correctly linked to the deal's close date property. Double-check that the property name exactly matches how it's defined in HubSpot. If needed, use the Add property button to make sure it's properly linked.

 

2. Data outputs. You have a variable called hs_execution_state as one of the outputs. This is typically used to track the execution status of your custom code action. Ensure that you have properly defined and are using this enumeration to track the success or failure of the action. You may want to make sure that your code correctly handles these outputs, especially if you're using a status like Succeeded or Failed.

 

If you're still encountering issues, I’d recommend testing the custom code in smaller parts or logging more details in the action to track the specific flow and see what might be going wrong.