💬 RevOps Discussions

RPerez14
Member

Deals Label Workflow Won't Branch Properly

SOLVE

issue workflow (unresponsive UI)issue workflow (unresponsive UI)correct workflow (responsive UI)correct workflow (responsive UI)custom property settingscustom property settingsI am trying to create a workflow that checks whether a deal has a primary company label or not, and then adds the deal to an active list to be manually reviewed. However, all the test cases end up going into "none met" and none of them go through "yes" or "no" branches as expected. I think there might be a problem when accessing the property. I created a boolean property that stores the output of the custom code, and I made sure that the output is in a dictionary and that the data output is explicitly declared. I've included the code below, as well pictures of what we're seeing. Please let me know how to fix this.

import requests PRIMARY_LABEL_ID = 1 def get_headers(api_key): return { 'Authorization': f'Bearer {api_key}', 'Content-Type': 'application/json' } def get_company_associations(deal_id, headers): url = f'https://api.hubapi.com/crm/v4/objects/deals/{deal_id}/associations/companies' params = {'limit': 100} response = requests.get(url, headers=headers, params=params) response.raise_for_status() return response.json().get('results', []) def has_primary_company(associations): for assoc in associations: label_ids = assoc.get('associationSpec', {}).get('labelIds', assoc.get('labelIds', [])) if PRIMARY_LABEL_ID in label_ids: return "Yes" return "No" def main(input): deal_id = input.get('inputFields', {}).get('hs_object_id') api_key = 'pat-na1-e08350ef-4f05-4dd1-8295-3d398d3fcd47' # replace with secure token in production if not api_key: return { "outputFields": { "primary_company_associated": "No", "error": "Missing HubSpot access token in secrets" } } if not deal_id: return { "outputFields": { "primary_company_associated": "No", "error": "Missing hs_object_id input field" } } try: headers = get_headers(api_key) associations = get_company_associations(deal_id, headers) is_primary = has_primary_company(associations) return { "outputFields": { "primary_company_associated": is_primary, "error": "YAY! no error" # always include error field for consistency } } except Exception as e: return { "outputFields": { "primary_company_associated": "No", "error": str(e) } }

0 Upvotes
2 Accepted solutions
karstenkoehler
Solution
Hall of Famer | Partner
Hall of Famer | Partner

Deals Label Workflow Won't Branch Properly

SOLVE

@RPerez14 

  1. Add branch: AND/OR logic
  2. Add criteria → change 'Filtering on' dropdown to 'Company'
  3. Under 'Company properties' find 'Record ID is known'
  4. Once selected, click here to specify association label and save:

karstenkoehler_0-1751025363212.png

 

Karsten Köhler
HubSpot Freelancer | RevOps & CRM Consultant | Community Hall of Famer

Beratungstermin mit Karsten vereinbaren

 

Did my post help answer your query? Help the community by marking it as a solution.

View solution in original post

0 Upvotes
MHolzer
Solution
Contributor

Deals Label Workflow Won't Branch Properly

SOLVE

@RPerez14 instead of using custom code try using a rollup property which counts the primary companies associated to the deal, the roll up property will already be calculated way before the deal goes into the workflow so its also easier for hubspot to not mess it up

looks like this:

MHolzer_1-1751373381651.png

 


instead of boolean yes/no you just use "0" for no primary company associated =No
and "1"for a primary company associated = Yes 

this is the easiest option and should always work

View solution in original post

0 Upvotes
8 Replies 8
MHolzer
Solution
Contributor

Deals Label Workflow Won't Branch Properly

SOLVE

@RPerez14 instead of using custom code try using a rollup property which counts the primary companies associated to the deal, the roll up property will already be calculated way before the deal goes into the workflow so its also easier for hubspot to not mess it up

looks like this:

MHolzer_1-1751373381651.png

 


instead of boolean yes/no you just use "0" for no primary company associated =No
and "1"for a primary company associated = Yes 

this is the easiest option and should always work

0 Upvotes
RPerez14
Member

Deals Label Workflow Won't Branch Properly

SOLVE

Hi @karstenkoehler , we don't know how to create the criteria of "Deal is associated to: Primary Company". We've gone to branch > one property or action output , and we searched for "primary company", associations, association labels, but we can't find the setting to check for primary company association labels. If this could work, then it would fix all of our problems.

0 Upvotes
karstenkoehler
Solution
Hall of Famer | Partner
Hall of Famer | Partner

Deals Label Workflow Won't Branch Properly

SOLVE

@RPerez14 

  1. Add branch: AND/OR logic
  2. Add criteria → change 'Filtering on' dropdown to 'Company'
  3. Under 'Company properties' find 'Record ID is known'
  4. Once selected, click here to specify association label and save:

karstenkoehler_0-1751025363212.png

 

Karsten Köhler
HubSpot Freelancer | RevOps & CRM Consultant | Community Hall of Famer

Beratungstermin mit Karsten vereinbaren

 

Did my post help answer your query? Help the community by marking it as a solution.

0 Upvotes
karstenkoehler
Hall of Famer | Partner
Hall of Famer | Partner

Deals Label Workflow Won't Branch Properly

SOLVE

Hi @RPerez14,

 

Happy to help here – why not just use a branch?

 

karstenkoehler_0-1751021253421.png

 

This would be a lot less prone to error.

 

Best regards!

Karsten Köhler
HubSpot Freelancer | RevOps & CRM Consultant | Community Hall of Famer

Beratungstermin mit Karsten vereinbaren

 

Did my post help answer your query? Help the community by marking it as a solution.

0 Upvotes
RPerez14
Member

Deals Label Workflow Won't Branch Properly

SOLVE

Hi @karstenkoehler, thank you for your response. We've tried that, and even when we hard-code the response and set it to "no", it still wouldn't go through the branch.

0 Upvotes
karstenkoehler
Hall of Famer | Partner
Hall of Famer | Partner

Deals Label Workflow Won't Branch Properly

SOLVE

@RPerez14 I'm not following, what do you mean by "hard-code the response and set it to no"?

 

In my proposed solution, you're not using any custom code at all because it's not needed, see my previous reply. You're using a branch to perform the check for you.

 

I'm confident that this works reliably as I have implemented this and currently in place in various HubSpot portals.

 

Best regards

Karsten Köhler
HubSpot Freelancer | RevOps & CRM Consultant | Community Hall of Famer

Beratungstermin mit Karsten vereinbaren

 

Did my post help answer your query? Help the community by marking it as a solution.

0 Upvotes
RPerez14
Member

Deals Label Workflow Won't Branch Properly

SOLVE

Hi @karstenkoehler , we don't know how to set the criteria to "Deal is associated to: primary company". We went to "branch" > "one property or action output", and we checked under deal properties, associated objects, but we couldn't find the criteria to match. If we could get the branch to work, it would fix all our problems.

0 Upvotes
karstenkoehler
Hall of Famer | Partner
Hall of Famer | Partner

Deals Label Workflow Won't Branch Properly

SOLVE

@RPerez14 I already replied to his, see here: https://community.hubspot.com/t5/128172-RevOps-Discussions/Deals-Label-Workflow-Won-t-Branch-Properl...

Karsten Köhler
HubSpot Freelancer | RevOps & CRM Consultant | Community Hall of Famer

Beratungstermin mit Karsten vereinbaren

 

Did my post help answer your query? Help the community by marking it as a solution.