CMS Development

ChrisChiha
Top Contributor

Associating and object to a custom object based on a property field

SOLVE

Hello All,
 
Anybody have a sample or a documentation for the below scenario?
I want to associate a custom object to a deal based on whether a certain property field in the deal matches another property field in the custom object.
 
So for example:
If deal.status = customobject.status, associate this custom objetc to the deal.
 
I am planning to do this through a js custom code, would really appreciate sharing some examples or documentations if any!
 
Thank you!
@ChrisChiha 

1 Accepted solution
LMeert
Solution
Guide | Platinum Partner
Guide | Platinum Partner

Associating and object to a custom object based on a property field

SOLVE

Hi @ChrisChiha,

 

The association is done through this API call :

/crm/v4/objects/{objectType}/{objectId}/associations/{toObjectType}/{toObjectId}
 
You have the objectId and when you run your search, you'll get the "toObjectId".
You're simply missing the objectTypes and to get them you can either make a call to get the object Schema of the object you're trying to associate OR you can also have a look at your settings :
LMeert_0-1664179865248.png

 

If you go to your custom objects, open the "associations" tab, you'll see in the url :
The objectType of your custom object will be the content of the url parameter "type" (in my case 2-1786212), and your toObjectType will be the content of the url parameter "selectToObjectTypeId" (in my case 0-1 for contacts).

There's an easier solution for you if you don't want to bother writing code : use the associ8 marketplace app, it lets you associate records based on a matching property.

It's free and so far I haven't had a problem with it.

 

Hope this helps !
If it does, please consider marking this answer as a solution 🙂

 

Best,

Ludwig

Agence Mi4 - Data DrivenCTO @ Mi4
Hubspot Platinum Partner and Integration Expert

Passionate human, very curious about everything data and automation.

Any problem with Hubspot you need help solving ?

Let me know !

View solution in original post

4 Replies 4
klloyd__1
Participant | Partner
Participant | Partner

Associating and object to a custom object based on a property field

SOLVE

Thanks for the tag @Jaycee_Lewis !

 

@ChrisChiha what you'll want to do is use the CRM Search API to find any existing deals with that matching property value.  I'm a little nervous about matching on something like status, since I assume there could be multiple Deals that all have the same status value.  If that's the case, you would probably want to add search criteria filters, to return on the specific deal you want.  If there's a match the CRM Search API would return the ID of the Deal record, which you could then associate to your custom object.

 

I'm more of a Python guy, but this is how you could structure your CRM Search API request to find a Deal by status, written using Javascript Jquery:

var settings = {
  "url": "https://api.hubapi.com/crm/v3/objects/deals/search?hapikey=xxxxxxx",
  "method": "POST",
  "timeout": 0,
  "headers": {
    "Content-Type": "application/json"
  },
  "data": JSON.stringify({
    "filterGroups": [
      {
        "filters": [
          {
            "operator": "EQ",
            "propertyName": "status",
            "value": "in_progress"
          }
        ]
      }
    ]
  }),
};

$.ajax(settings).done(function (response) {
  console.log(response);
});

 

Let me know if this helps!

ChrisChiha
Top Contributor

Associating and object to a custom object based on a property field

SOLVE

Hello @klloyd__1 ,

 

Thanks for your reply!

 

Actually my main challenge is associating the custom object to the deal after i find the deal that has the matching property fied. I am using a custom object based workflow, and i am trying to associate the enrolled custom object to the deal i found.

 

Thank you loads!

@ChrisChiha 

LMeert
Solution
Guide | Platinum Partner
Guide | Platinum Partner

Associating and object to a custom object based on a property field

SOLVE

Hi @ChrisChiha,

 

The association is done through this API call :

/crm/v4/objects/{objectType}/{objectId}/associations/{toObjectType}/{toObjectId}
 
You have the objectId and when you run your search, you'll get the "toObjectId".
You're simply missing the objectTypes and to get them you can either make a call to get the object Schema of the object you're trying to associate OR you can also have a look at your settings :
LMeert_0-1664179865248.png

 

If you go to your custom objects, open the "associations" tab, you'll see in the url :
The objectType of your custom object will be the content of the url parameter "type" (in my case 2-1786212), and your toObjectType will be the content of the url parameter "selectToObjectTypeId" (in my case 0-1 for contacts).

There's an easier solution for you if you don't want to bother writing code : use the associ8 marketplace app, it lets you associate records based on a matching property.

It's free and so far I haven't had a problem with it.

 

Hope this helps !
If it does, please consider marking this answer as a solution 🙂

 

Best,

Ludwig

Agence Mi4 - Data DrivenCTO @ Mi4
Hubspot Platinum Partner and Integration Expert

Passionate human, very curious about everything data and automation.

Any problem with Hubspot you need help solving ?

Let me know !

Jaycee_Lewis
Community Manager
Community Manager

Associating and object to a custom object based on a property field

SOLVE

Hi, @ChrisChiha 👋 Thanks for reaching out. It's a great question. Let's see if we can get the conversation started. Hey @LMeert @Gonzalo @klloyd__1 have you tackled anything similar?

 

Thank you very much! — Jaycee

linkedin

Jaycee Lewis

Developer Community Manager

Community | HubSpot

0 Upvotes