CMS Development

ChrisChiha
Top colaborador(a)

Automated Email - Populated using HubDB & HubL

resolver

Hello,

  
I am sending a daily digest to my partners that is being populated from my hubdb table, and is being triggered by a workflow. (The HubDB table is being filled daily from my Backend)

  
How it is currently working:

If the email address enrolled in the wokflow, is found in the HubDB table, then the row is fetched to the communication. The daily digest is working great right now, but now, even if the email address is not found in the hubdb table, the email is enrolled in the wokrflow.

  

I would like to know if it is possible to only send the email to enrolled people in the workflow, if their email address is present in the hubdb table.
I have a list of partners that are being enrolled in my workflow. Ideally, what i want to achieve; If the enrolled partner email is not found in the HubDB table column "email", i don't want the email communication to be triggered to him. is this possible?

   

Another question i had in mind:
Is it possible to trigger a workflow when a new row is added to the hubdb table ?

0 Avaliação positiva
1 Solução aceita
Teun
Solução
Especialista reconhecido(a) | Parceiro Diamante
Especialista reconhecido(a) | Parceiro Diamante

Automated Email - Populated using HubDB & HubL

resolver

Hi @ChrisChiha ,

 

I wrote this real quick, so could be some errors, but it could look something like this:

const axios = require('axios');

exports.main = async (event, callback) => {
  const email = event.inputFields['email'];
  let rowFound = false

  const result = await axios({
    method: 'get',
    headers: { 'content-type': 'application/json' },
    url: `https://api.hubapi.com/cms/v3/hubdb/tables/${tableId}/rows?portalId=${portalId}&limit=1&email__eq=${email}`,
  }).then((response) => {
    console.log(response.data)
    if (response.data && response.data.results) {
      rowFound = true
    }
  }).catch((error) => {
    console.log(error)
  })

  callback({
    outputFields: {
      rowFound: rowFound
    }
  });
}

You can then use the 'rowFound' property in the output to handle the following steps of your workflow (you might have to use the Copy to Property action first).



Learn more about HubSpot by following me on LinkedIn or YouTube

Did my answer solve your issue? Help the community by marking it as the solution.


Exibir solução no post original

6 Respostas 6
Teun
Especialista reconhecido(a) | Parceiro Diamante
Especialista reconhecido(a) | Parceiro Diamante

Automated Email - Populated using HubDB & HubL

resolver

Hi @ChrisChiha ,

 

Do you have Operations Hub? If so, you can write a coded action that checks if a row exists and you can use the output to create a if / then branch to decide if you want to send the e-mail.



Learn more about HubSpot by following me on LinkedIn or YouTube

Did my answer solve your issue? Help the community by marking it as the solution.


ChrisChiha
Top colaborador(a)

Automated Email - Populated using HubDB & HubL

resolver

Hello @Teun,
 
Yes that's what i was trying to achieve, adding a custom code at the beginning of the workflow to check if the email is found in any of the hubdb table rows.
  
I have operations hub and marketing enterprise.
  
Do you have any sample or documentation that might help/guide me in writing this custom code?

   

Thank you!

@ChrisChiha 

Teun
Solução
Especialista reconhecido(a) | Parceiro Diamante
Especialista reconhecido(a) | Parceiro Diamante

Automated Email - Populated using HubDB & HubL

resolver

Hi @ChrisChiha ,

 

I wrote this real quick, so could be some errors, but it could look something like this:

const axios = require('axios');

exports.main = async (event, callback) => {
  const email = event.inputFields['email'];
  let rowFound = false

  const result = await axios({
    method: 'get',
    headers: { 'content-type': 'application/json' },
    url: `https://api.hubapi.com/cms/v3/hubdb/tables/${tableId}/rows?portalId=${portalId}&limit=1&email__eq=${email}`,
  }).then((response) => {
    console.log(response.data)
    if (response.data && response.data.results) {
      rowFound = true
    }
  }).catch((error) => {
    console.log(error)
  })

  callback({
    outputFields: {
      rowFound: rowFound
    }
  });
}

You can then use the 'rowFound' property in the output to handle the following steps of your workflow (you might have to use the Copy to Property action first).



Learn more about HubSpot by following me on LinkedIn or YouTube

Did my answer solve your issue? Help the community by marking it as the solution.


ChrisChiha
Top colaborador(a)

Automated Email - Populated using HubDB & HubL

resolver

Hello @Teun ,

 
I was able to get this code working, but it is always returning True even when there is no match. The outcome is right (Giving me 0 matches), but the code is still considering as True. I guess the problem is with the If statement, as it is considering any log as "True", even if the log is showing no matches.
  
Screen Shot 2022-05-30 at 7.22.26 AM.png

    

    

UPDATE:
It worked, just had to replace the if statement by the below. Thank you !!

   

if (response.data.total > 0) {
rowFound = true
}

0 Avaliação positiva
Teun
Especialista reconhecido(a) | Parceiro Diamante
Especialista reconhecido(a) | Parceiro Diamante

Automated Email - Populated using HubDB & HubL

resolver

Awesome! Happy you got it working!



Learn more about HubSpot by following me on LinkedIn or YouTube

Did my answer solve your issue? Help the community by marking it as the solution.


dennisedson
Equipe de Produto da HubSpot
Equipe de Produto da HubSpot

Automated Email - Populated using HubDB & HubL

resolver

@ChrisChiha 

This sounds like an interesting project!

Going to  throw a few folks into this to see what comes of it

@tmcmillan99 , @Anton , @Josh , @ChrisoKlepke  what do you all think?

@tmcmillan99  and @ChrisoKlepke  are already having an interesting discussion on Custom Objects vs HubDB 😀