Dashboards & Reporting

GustavoGGomes
Participant

Workflow - Deal without associated Company

SOLVE

Hello all, 

Is there any way I can trigger a workflow when a deal is created without an associated company? I want to create a task for the deal owner to fix this and associate the correct account. 

Thanks!

2 Accepted solutions
Bryantworks
Solution
Key Advisor | Diamond Partner
Key Advisor | Diamond Partner

Workflow - Deal without associated Company

SOLVE

Hey @GustavoGGomes,

 

Unfortunately, it doesn't look like this is possible - I don't see any properties you could trigger that captures associated Company on the deal record itself.  Just a "Number of Contacts" which you could use to identify a deal with no contact associated.  

Chris Bryant | Your Dedicated HubSpot Expert

View solution in original post

warrendavey
Solution
Top Contributor | Diamond Partner
Top Contributor | Diamond Partner

Workflow - Deal without associated Company

SOLVE

@GustavoGGomes - Awesome Question! I figured out a way you can do this with just 2 workflows and one custom field.  I answered this in my question of the day video.

 

https://youtu.be/LyOSlKsZXM4

 

Because "Associated Company" is not a field in Deals you can't use it as a criteria piece to trigger a workflow. But you can use a workflow from Company to see if they have any associated deals and then have it populate a copied field on those deals.  If your deal never populates, because it has no association, then you can assume it is missing the company association, and with a delayed trigger notify your team to update the record.

 

Hope that helps!

✔️ Was I able to help answer your question? Help the community by marking it as a solution.

Davey Waren
Pearagon

Still have questions? Let's Talk

View solution in original post

7 Replies 7
CHigueras
Participant

Workflow - Deal without associated Company

SOLVE

Hi @GustavoGGomes 

 

I guess this was asked a long time ago. But I manage to trigger the workflow when a deal is created without any associated company using the workflow's custom code section. I will add here in case other people may need this in the future.

 

1. First you need to have an Private APP access token. In case you don't have it already, go to: Settings > Account Setup > Integrations > Private APPs and create a new private app.

 

2. Create a new deal based workflow.

 

2.1 In my case I am using Record ID is Known as "Deal Enrollment Trigger".

 

2.2 On the next step, select custom code.

 

2.3 In the "Secrets" section, add a new secret, name it API_ACCESS_TOKEN and copy the token from step 1 in the "Secret Value" input.

 

Screenshot from 2023-08-09 18-02-49.png

 

The secret you have created should be selected in the input box, as in the imageThe secret you have created should be selected in the input box, as in the image

 

2.4 In the code section, copy the following code:

 

 

const hubspot = require('@hubspot/api-client');

exports.main = async (event, callback) => {
  const hubspotClient = new hubspot.Client({
    accessToken: process.env.API_ACCESS_TOKEN //this is the name of the secret you have selected
  });

  let getCompanies = (dealId) => {
    return hubspotClient.crm.deals.associationsApi.getAll(dealId, 'company');
  }
  
  try {
    const dealId = event.object.objectId;
    /** Company */
    const companies = await getCompanies(dealId);
    let companyId = null;
    if (companies.results.length) {
      companies.results.forEach((el) => {
        companyId = el.toObjectId;
        return;
      });
    }
    
    callback({
      outputFields: {
		hasCompany: !!companyId
      }
    });
  } catch (err) {
    console.error(err);
    // We will automatically retry when the code fails because of a rate limiting error from the HubSpot API.
    throw err;
  }
}

 

 

Screenshot from 2023-08-09 18-04-40.png

 

What we are doing above is load the Deal object and find if it has any associated company. So we add to the callback an output hasCompany that can be true or false. Now we need to use the output from the code within the workflow.

 

2.5 In the output section, click on "add output" and select Boolean as Data Type and add hasCompany in the Name input

 

Screenshot from 2023-08-09 18-05-20.png

 

2.6 Now we already have the custom code output available in our workflow. So add a new step of the type "Branch" and choose the option "Based on single property value (value equals)".

 

Screenshot from 2023-08-09 18-06-14.png

 

In the property input, scroll down to the Action Outputs > Custom Code section and select hasCompany and click next.

 

Screenshot from 2023-08-09 18-06-46.png

 

On branch 1 select the option "no" and save.

 

Screenshot from 2023-08-09 18-07-22.png

 

Now you can already do any desired actions with the workflow when a deal has no company.

 

Screenshot from 2023-08-09 18-22-49.png

 

warrendavey
Solution
Top Contributor | Diamond Partner
Top Contributor | Diamond Partner

Workflow - Deal without associated Company

SOLVE

@GustavoGGomes - Awesome Question! I figured out a way you can do this with just 2 workflows and one custom field.  I answered this in my question of the day video.

 

https://youtu.be/LyOSlKsZXM4

 

Because "Associated Company" is not a field in Deals you can't use it as a criteria piece to trigger a workflow. But you can use a workflow from Company to see if they have any associated deals and then have it populate a copied field on those deals.  If your deal never populates, because it has no association, then you can assume it is missing the company association, and with a delayed trigger notify your team to update the record.

 

Hope that helps!

✔️ Was I able to help answer your question? Help the community by marking it as a solution.

Davey Waren
Pearagon

Still have questions? Let's Talk

VAtuyer
Participant

Workflow - Deal without associated Company

SOLVE

Hi @warrendavey 
Many thanks for your help and the video!
However, in the Workflow menu, I can't find the same settings as you do in your video.

1) Company-based workflow 

2) I look for "Deal information" ==> Associated Deal ==> Nothing appears, compared to your screen

Below is where I am:

Screenshot 2023-08-25 at 10.31.59 AM (2).png

 How can you set up this workflow?

Thanks

0 Upvotes
AndreaMilani
Contributor

Workflow - Deal without associated Company

SOLVE

@warrendavey it doesn't look like the property "Associated Deals" is available on the Company object, I can see only "Number of Associated Deals". Is it something that was deprecated since 2020 when you made the video?

0 Upvotes
AdamAllcock
Member

Workflow - Deal without associated Company

SOLVE

The limitation of this is it will not detect deals that used to have a company associated but no longer do, as Company Name is not going to be cleared.

 

If you really want to detect this, you can create a helper field on the company level and deal level (can just be 1, doesn't matter). Every day, the company field is incremented by 1 (or flicks between 1 and 0 with if statements), and is then copied from the company to the deal level. deal. On the deal side, you can then have a workflow which triggers if the deal's helper field has not been updated in the last 24 hours. 

 

Alternatively, you can copy across from the company a 'today' field, and then on the deal level every day check if its not equal to today.


[If you want less workflow spam on the deal records, you can also update the company field every 7 days and run the workflow if now updated in 8 days etc. Or set your daily company workflow to only update on deals that have not had their number of associated deals changed in the last 24 hours]

 

@GustavoGGomes @Bryantworks @warrendavey 

0 Upvotes
Bryantworks
Solution
Key Advisor | Diamond Partner
Key Advisor | Diamond Partner

Workflow - Deal without associated Company

SOLVE

Hey @GustavoGGomes,

 

Unfortunately, it doesn't look like this is possible - I don't see any properties you could trigger that captures associated Company on the deal record itself.  Just a "Number of Contacts" which you could use to identify a deal with no contact associated.  

Chris Bryant | Your Dedicated HubSpot Expert
GustavoGGomes
Participant

Workflow - Deal without associated Company

SOLVE

Hi @Bryantworks

Yes, I also realized that there isn't anything that can help to trigger this, but wanted to double-check it. 
Thanks for your attention!