CMS Development

ChrisChiha
Contributeur de premier rang

Automated Email - Populated using HubDB & HubL

SOLVE

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 Upvotes
1 Accepted solution
Teun
Solution
Key Advisor | Diamond Partner
Key Advisor | Diamond Partner

Automated Email - Populated using HubDB & HubL

SOLVE

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).



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

View solution in original post

6 Replies 6
Teun
Key Advisor | Diamond Partner
Key Advisor | Diamond Partner

Automated Email - Populated using HubDB & HubL

SOLVE

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.



Did my answer solve your issue? Help the community by marking it as the solution.
ChrisChiha
Contributeur de premier rang

Automated Email - Populated using HubDB & HubL

SOLVE

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
Solution
Key Advisor | Diamond Partner
Key Advisor | Diamond Partner

Automated Email - Populated using HubDB & HubL

SOLVE

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).



Did my answer solve your issue? Help the community by marking it as the solution.
ChrisChiha
Contributeur de premier rang

Automated Email - Populated using HubDB & HubL

SOLVE

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 Upvotes
Teun
Key Advisor | Diamond Partner
Key Advisor | Diamond Partner

Automated Email - Populated using HubDB & HubL

SOLVE

Awesome! Happy you got it working!



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

Automated Email - Populated using HubDB & HubL

SOLVE

@ChrisChiha 

This sounds like an interesting project!

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

@tmcmillan99 , @Anton , @Josh , @Chriso-mwx  what do you all think?

@tmcmillan99  and @Chriso-mwx  are already having an interesting discussion on Custom Objects vs HubDB 😀

Thanks,

Dennis




HubSpot Community Developer ShowMake sure to subscribe to our YouTube channel
where you can find the HubSpot Community Developer Show