How to Show CRM Object Property Values in a Module

I have a custom object called Resorts.
In a module, I did it like this:

{% set query = “limit=”~10~“&offset=0” %}
{% set crm_data = crm_objects(“resorts”, query, “hs_object_id, booked_dates, resort_name, description, overall_review_score, overall_review_status, total_reviews_received, images, images_urls, logo, logo_urls, temporary_url, country_select, city, specialties”) %}
{% set all_crm_resort = crm_data.results %}

<pre>{{all_crm_resort}}</pre>
Although its showing the data in the preview, but I’m not being able to save it because its showing me this error in the console:

Error:Unable to validate template at this time. Please try again.

And also how to show this CRM data with JavaScript?

Hi @MUlHuq,
I’ve a feeling there might be a bug cropping up at the moment. This is the second crm_objects related post we’ve seen in the last day or so.
And in testing I’m seeing similar issues with even the most basic of requests.

{% set objects = crm_objects("contact") %}
{{ objects }} 

gives the error

Error:Unable to validate template at this time. Please try again.

And cannot be published. But same as in your case the data shows in the preview.
Edit: oh, you were the other post. But still, I’m able to replicate the issue.


Barry Grennan

Freelance HubSpot CMS Developer

Website | Contact | LinkedIn

Yes, I think its an issue from Hubspot’s end.
I need to manipulate these values in JS. But somehow it’s showing an error.
For example, in my case, I was able to log out the whole data, which returned me an array of objects like this:
<script>
const allResorts = {{all_crm_resort | tojson}};
console.log(allResorts);
</script>
But right now its showing me this error:

java.lang.StackOverflowErrorOriginating Exception: StackOverflowError:
I don’t know why its happening.

  1. Minimize the Fields You Fetch

{% set query = “limit=10&offset=0” %}
{% set crm_data = crm_objects(“resorts”, query, “hs_object_id, resort_name, city, country_select”) %}
{% set all_crm_resort = crm_data.results %}

Then:
<script>
const allResorts = {{ all_crm_resort | tojson }};
console.log(allResorts);
</script>

2. Convert Individual Properties to JSON

{% set resorts_js_data = [] %}
{% for resort in all_crm_resort %}
{% do resorts_js_data.append({
“id”: resort.hs_object_id,
“name”: resort.resort_name,
“city”: resort.city,
“country”: resort.country_select
}) %}
{% endfor %}

Then:

<script>
const allResorts = {{ resorts_js_data | tojson }};
console.log(allResorts);
</script>

3. Paginate or Limit the Results Further

<script>
const resorts = {{ [{“name”: “Test Resort”, “city”: “Sample City”}] | tojson }};
console.log(resorts);
</script>

@MUlHuq
Weirdly, what I’m finding works is:
- Select all your code (I’m in a module, so it’s in module.html)
- Cut it
- Paste it back in again
- Publish


Barry Grennan

Freelance HubSpot CMS Developer

Website | Contact | LinkedIn

Yup, I think they fixed the issue. Everything is working now.
Thanks for the updates.

Hello @MUlHuq

Wrap the code inside a {% if crm_data is defined %} or {% if all_crm_resort %} block. Example:

{% set query = “limit=10&offset=0” %}
{% set crm_data = crm_objects(“resorts”, query, “hs_object_id, booked_dates, resort_name, description, overall_review_score, overall_review_status, total_reviews_received, images, images_urls, logo, logo_urls, temporary_url, country_select, city, specialties”) %}
{% if crm_data and crm_data.results %}
{% set all_crm_resort = crm_data.results %}
<pre>{{ all_crm_resort|pprint }}</pre>
{% else %}
<p>No data found or error in fetching CRM objects.</p>
{% endif %}