⚙ Operations Hub

Isabel_c
Contributor

Custom code Make contact property input fields from a form submission to search in company property

Hi, 

 

I have been dealing with this problem for 2days already and all my codes did not work.

 

When a visitor makes a form submission, it will fill up a contact property called "shop_number" as a single line text. And;

 

because it is a single line text, I can't use the filtering because I will have to input all 7000 values which copy and pasting does not work.

 

On a custom code, we want this input fields to search on company property, also called, "shop_number" to filter the response if matched to any of all the companies in the crm.

 

For example: A visitor submitted '12340' in the contact shop number, then the workflow should be able to check if that matches any of the company shop number. The answer must be boolean.

 

Hoping for someone's help please

 

3 Replies 3
Isabel_c
Contributor

Custom code Make contact property input fields from a form submission to search in company property

closing this

0 Upvotes
Shadab_Khan
Key Advisor | Elite Partner
Key Advisor | Elite Partner

Custom code Make contact property input fields from a form submission to search in company property

Hi @Isabel_c ,

 

I am not a developer (aspiring one though 💪🏻) so I did some GPT-4 and here's what I got.


Trigger Workflow: Trigger the workflow when a form is submitted that updates the shop_number property for a contact.

const hubspot = require('@hubspot/api-client');
const hubspotClient = new hubspot.Client({ apiKey: 'YOUR_HUBSPOT_API_KEY' });

exports.main = (event, callback) => {
  const contactShopNumber = event.object.properties.shop_number;

  hubspotClient.crm.companies.searchApi.doSearch({
    filterGroups: [{
      filters: [{
        propertyName: 'shop_number',
        operator: 'EQ',
        value: contactShopNumber
      }]
    }]
  }).then(results => {
    const isMatch = results.body.total > 0;
    callback({ output: { isMatch } });
  }).catch(err => {
    console.error(err);
    callback({ output: { isMatch: false } });
  });
};

 

you can further, diagnose your own code with GPT and get some movement while you wait for a developer's response.

Also, I recommend posting this on the developer discussion for better visibility.

Found my solution helpful? mark it as accepted

Isabel_c
Contributor

Custom code Make contact property input fields from a form submission to search in company property

I tried the code but it did not work on my end. Thanks though

0 Upvotes