CRM Object Filtering

Hi hubspot community,

Trying to filter my object records by type of publication. Did this a very repetitive way that worked but then hit the CRM object call limit so had to work out how to consolidate the code.

Stuck on trying to filter results further and came up with {% set associated_objects(“type_of_publication=Book Chapter”) %} but I feel like this is wrong. Assume this is something easy to fix. At the moment the code is just outputting all the records associated with the person and using the first filter but not including the filter in the second “set”.

Sample code for first two publication types below.

Appreciate the support. Thanks in advance. :blush:

 <h5>Research Publications</h5>
{% set associated_objects = crm_associations(module.person.id, "USER_DEFINED", 209, "research_or_scholarship_publication_=Research Publication&visible_publication=true&orderBy=-year_published", "publication_title, year_published, books_book_chapters_music__publisher_name_and_place, name_of_author_s_, book_chapter__book_name, book_chapters_journals__page_numbers, journal__name, journal__volume_and_issue, publication_external_link, conference_creative_performance__name_of, conference_creative_performance__location") %} 
<h6>Books</h6>
{% for ac_profiles in associated_objects.results %} {% set associated_objects("type_of_publication=Books") %}
	{{ac_profiles.name_of_author_s_}} ({{ac_profiles.year_published}}). <em>{{ ac_profiles.publication_title }}</em>. {{ac_profiles.books_book_chapters_music__publisher_name_and_place}}<br> 
{% endfor %}
<br>
<h6>Book Chapters</h6>
{% for ac_profiles in associated_objects.results %} {% set associated_objects("type_of_publication=Book Chapter") %}
{{ac_profiles.name_of_author_s_}} ({{ac_profiles.year_published}}). <em>{{ ac_profiles.publication_title }}</em> in {{ ac_profiles.book_chapter__book_name}} (pp.{{ac_profiles.book_chapters_journals__page_numbers}}). {{ac_profiles.books_book_chapters_music__publisher_name_and_place}}<br>
{% endfor %}

Hi, @Luke-Simp :waving_hand: Thanks for reaching out! Hey, @Stephanie-OG @Anton, do you have any tips you can share with @Luke-Simp?

Thank you very much for taking a look! — Jaycee

Thanks @Jaycee_Lewis. Still having issues when I’m combining multiple modules and hitting crm_associations call limit with this so if anyone is able to give insight that would be awesome!

Here’s the latest code. Would love to just do one call for the whole “Scholarships” section and then just filter by “type_of_publication” to show the different results for each subheading.

Appreciate any feedback.

<details>
 <summary>
 <h5>Scholarship</h5>
 <div class="chevron-icon"></div>
 </summary>
 <div class="content-wrapper">
 {% if dynamic_page_crm_object %}
{% set associated_objects = crm_associations(dynamic_page_crm_object.id, "USER_DEFINED", 211, "research_or_scholarship_publication_=Scholarship Publication&type_of_publication=Book&visible_publication=true&orderBy=-year_published", "publication_title, year_published, books_book_chapters_music__publisher_name_and_place, name_of_author_s_, book_chapter__book_name, book_chapters_journals__page_numbers, conference_creative_performance__name_of, conference_creative_performance__location, publication_external_link, journal__name, journal__volume_and_issue") %}
 <h6>Books</h6>
{% for ac_profiles in associated_objects.results %}
	{{ac_profiles.name_of_author_s_}} ({{ac_profiles.year_published}}). <em>{{ ac_profiles.publication_title }}</em>. {{ac_profiles.books_book_chapters_music__publisher_name_and_place}}<br> 
{% endfor %} 
<br>
{% set associated_objects = crm_associations(dynamic_page_crm_object.id, "USER_DEFINED", 211, "research_or_scholarship_publication_=Scholarship Publication&type_of_publication=Book chapter&visible_publication=true&orderBy=-year_published", "publication_title, year_published, books_book_chapters_music__publisher_name_and_place, name_of_author_s_, book_chapter__book_name, book_chapters_journals__page_numbers, conference_creative_performance__name_of, conference_creative_performance__location, publication_external_link, journal__name, journal__volume_and_issue") %}
 <h6>Book Chapters</h6>
{% for ac_profiles in associated_objects.results %} 
{{ac_profiles.name_of_author_s_}} ({{ac_profiles.year_published}}). <em>{{ ac_profiles.publication_title }}</em> in {{ ac_profiles.book_chapter__book_name}} (pp.{{ac_profiles.book_chapters_journals__page_numbers}}). {{ac_profiles.books_book_chapters_music__publisher_name_and_place}}<br>
{% endfor %} 
<br>
{% set associated_objects = crm_associations(dynamic_page_crm_object.id, "USER_DEFINED", 211, "research_or_scholarship_publication_=Scholarship Publication&type_of_publication=Book Review&visible_publication=true&orderBy=-year_published", "publication_title, year_published, books_book_chapters_music__publisher_name_and_place, name_of_author_s_, book_chapter__book_name, book_chapters_journals__page_numbers, conference_creative_performance__name_of, conference_creative_performance__location, publication_external_link, journal__name, journal__volume_and_issue") %} 
 <h6>Book Reviews</h6>
{% for ac_profiles in associated_objects.results %} 
	{{ac_profiles.name_of_author_s_}} ({{ac_profiles.year_published}}). <em>{{ ac_profiles.publication_title }}</em>. {{ac_profiles.books_book_chapters_music__publisher_name_and_place}}<br> 
{% endfor %} 
<br>
{% set associated_objects = crm_associations(dynamic_page_crm_object.id, "USER_DEFINED", 211, "research_or_scholarship_publication_=Scholarship Publication&type_of_publication=Creative Production or Composition&visible_publication=true&orderBy=-year_published", "publication_title, year_published, books_book_chapters_music__publisher_name_and_place, name_of_author_s_, book_chapter__book_name, book_chapters_journals__page_numbers, conference_creative_performance__name_of, conference_creative_performance__location, publication_external_link, journal__name, journal__volume_and_issue") %}
 <h6>Creative Productions or Compositions</h6>
 {% for ac_profiles in associated_objects.results %} 
 {{ac_profiles.name_of_author_s_}} ({{ac_profiles.year_published}}). <em>{{ ac_profiles.publication_title }}</em>. {{ac_profiles.books_book_chapters_music__publisher_name_and_place}} {{ac_profiles.conference_creative_performance__location}}<br>
{% endfor %} 
<br>
{% set associated_objects = crm_associations(dynamic_page_crm_object.id, "USER_DEFINED", 211, "research_or_scholarship_publication_=Scholarship Publication&type_of_publication=Edited Collection of Essays&visible_publication=true&orderBy=-year_published", "publication_title, year_published, books_book_chapters_music__publisher_name_and_place, name_of_author_s_, book_chapter__book_name, book_chapters_journals__page_numbers, conference_creative_performance__name_of, conference_creative_performance__location, publication_external_link, journal__name, journal__volume_and_issue") %}
 <h6>Edited Collections of Essays</h6>
 {% for ac_profiles in associated_objects.results %}
 {{ac_profiles.name_of_author_s_}} ({{ac_profiles.year_published}}). <em>{{ ac_profiles.publication_title }}</em>. {{ac_profiles.books_book_chapters_music__publisher_name_and_place}}<br>
{% endfor %} 
<br>
{% set associated_objects = crm_associations(dynamic_page_crm_object.id, "USER_DEFINED", 211, "research_or_scholarship_publication_=Scholarship Publication&type_of_publication=Journal article&visible_publication=true&orderBy=-year_published", "publication_title, year_published, books_book_chapters_music__publisher_name_and_place, name_of_author_s_, book_chapter__book_name, book_chapters_journals__page_numbers, conference_creative_performance__name_of, conference_creative_performance__location, publication_external_link, journal__name, journal__volume_and_issue") %}
<h6>Journal Articles</h6>
 {% for ac_profiles in associated_objects.results %}
 {{ac_profiles.name_of_author_s_}} ({{ac_profiles.year_published}}). {{ ac_profiles.publication_title }}. <em>{{ac_profiles.journal__name}}</em>, {{ac_profiles.journal__volume_and_issue}}, {{ac_profiles.book_chapters_journals__page_numbers}} | <a href="{{ac_profiles.publication_external_link}}">External Link</a><br>
{% endfor %} 
<br>
{% set associated_objects = crm_associations(dynamic_page_crm_object.id, "USER_DEFINED", 211, "research_or_scholarship_publication_=Scholarship Publication&type_of_publication=Popular article&visible_publication=true&orderBy=-year_published", "publication_title, year_published, books_book_chapters_music__publisher_name_and_place, name_of_author_s_, book_chapter__book_name, book_chapters_journals__page_numbers, conference_creative_performance__name_of, conference_creative_performance__location, publication_external_link, journal__name, journal__volume_and_issue") %}
<h6>Popular Articles</h6>
 {% for ac_profiles in associated_objects.results %}
 {{ac_profiles.name_of_author_s_}} ({{ac_profiles.year_published}}). {{ ac_profiles.publication_title }}. <em>{{ac_profiles.journal__name}}</em> | <a href="{{ac_profiles.publication_external_link}}">External Link</a><br>
{% endfor %} 
<br>
{% set associated_objects = crm_associations(dynamic_page_crm_object.id, "USER_DEFINED", 211, "research_or_scholarship_publication_=Scholarship Publication&type_of_publication=Other publications&visible_publication=true&orderBy=-year_published", "publication_title, year_published, books_book_chapters_music__publisher_name_and_place, name_of_author_s_, book_chapter__book_name, book_chapters_journals__page_numbers, conference_creative_performance__name_of, conference_creative_performance__location, publication_external_link, journal__name, journal__volume_and_issue") %}
<h6>Other Publications</h6>
 {% for ac_profiles in associated_objects.results %}
 {{ac_profiles.name_of_author_s_}} ({{ac_profiles.year_published}}). <em>{{ ac_profiles.publication_title }}</em>. {{ac_profiles.books_book_chapters_music__publisher_name_and_place}} | <a href="{{ac_profiles.publication_external_link}}">External Link</a><br>
{% endfor %} 

 {% endif %}
 </div>
 </details>