DocMergy: Get Associated Objects (Contact and Deal Examples)

Learn about the DocMergy Get associated objects

Here are the different features for 'Get associated objects' within DocMergy, all with native HubSpot properties 

 

Contact Examples 

Get singular version

Get the associated deal name from the current contact

{{ get_associated_objects("contact", object.hs_object_id, "deal")[0].dealname }}  

  • It shows the name of the first deal associated with the current contact.
  • The function get_associated_objects takes 4 arguments

    • "contact": is the source object of the association
    • object.hs_object_id: the id of the source object, here it is the enrolled object ID
    • "deal" the associated object type you want to get data from
    • The last argument is "order_by" and is the property you want to use for ordering the list of "deals".
    • The [0] tells DocMergy to only grab the first associated deal you can here use [1] if you want the second one or [-1] if you want the last one
    • Dealname is the internal property name of the "deal" you want to display
    • Finally the {{ }} around it are telling DocMergy to render the property in the document

For loop version 

Screenshot 2025-04-11 161347

  • This loops through all notes on the first deal associated with the contact, and shows each note’s content and creation date.
  • {{ n.hs_note_body}} : this shows the body text of each note

  • {{ n.hs_createdate }} : this shows the date the note was create

  • .hs_object_id: gets the ID of that specific deal you just selected, which becomes the new source for the next association.

  • "notes" (in the outer function): is the associated object type you're getting from the deal — here, you're pulling all notes linked to the selected deal.

  • The outer get_associated_objects(...) returns a list of notes.

  • {% for n in ... %} : starts a loop through each of those notes, and allows you to work with each note using the variable n


 

For loop images

JPEG/JPG

Screenshot 2025-04-11 161741

  • This code loops through the line items on the first deal linked to the current contact and displays each item's name, description, image and image text
  • object.hs_object_id: is the ID of the source object — in this case, the enrolled contact in the workflow or document.
  • "deal" (inside the inner get_associated_objects): is the associated object type you're pulling from the contact — this gets all deals associated with the contact.
  • The [0] tells DocMergy to only grab the first associated deal. You can change it to [1] for the second deal, or [-1] for the last one.
  • .hs_object_id: gets the unique ID of that specific deal, which becomes the new base object to search from.
  • "line_items" (in the outer function): is the associated object type you're retrieving from the selected deal — you're asking for all line items linked to that deal.
  • The outer get_associated_objects(...) returns a list of line items.
  • {% for li in ... %} : starts a loop through those line items and stores each one as the variable li, which you can use inside the loop.
  • {{ li.name }} : This shows the name of the line item — like a product name or service title.
  • {{ li.description }} : This displays the description of the line item — more details about what it is or includes.
  • {{ li.image_text }} : This is a custom property or text representation of an image (if your line item has one). Could be used to show alt text or a URL reference, depending on how your setup stores it.

Deal Examples 

Get Associated Objects

Get singular version

  • The code gets the first contact associated with the deal and returns their first name

{{ get_associated_objects("deal", object.hs_object_id, "contact")[0].firstname }}  

 

The function get_associated_objects takes 4 arguments

  1. "deal": is the source object of the association
  2. object.hs_object_id: the id of the source object, here it is the enrolled object ID
  3. "contact" the associated object type you want to get data from
  4. The last argument is "order_by" and is the property you want to use for ordering the list of "deals". 
  • The [0] tells DocMergy to only grab the first associated deal you can here use [1] if you want the second one or [-1] if you want the last one
  • Firstname is the internal property name of the "contact" you want to display
  • The {{ }} around it are telling DocMergy to render the property in the document


For loop version
  • For every contact associated with the current deal, show their first name and email address

Screenshot 2025-04-16 125533

  • "deal": is the source object — you're starting from a deal.
  • object.hs_object_id: is the ID of that source object — in this case, the enrolled deal.
  • "contact": is the associated object type — you're retrieving all contacts linked to this deal.
  • get_associated_objects(...): returns a list of associated contacts.
  • {% for n in ... %}: starts a loop through those contacts, storing each one as the variable n.  
  • {{ n.firstname }} : displays the first name of the associated contact.
  • {{ n.email }} : displays the email address of that contact.

 

For loop images

  • This code loops through all line items associated with a deal and displays the line item name, description as well as the image and image text

Screenshot 2025-04-16 125751

  • "line_items": is the associated object type — you're asking DocMergy to get all line items linked to the deal.
  • get_associated_objects(...): fetches a list of all associated line items for that deal.
  • {% for li in ... %} : starts a loop, going through each line item and storing it as the variable li.
  • {{ li.name }} : shows the name of the line item — like a product or service title.
  • {{ li.description }} : shows the description — more detail about what the item includes.
  • {{ li.image_text }} : shows any text-based info related to an image (like alt text, filename, or a URL depending on your setup)