Use CRM data in JS

tommitchell
Contributor

Hi - sorry if this is a daft question but I'm trying to work out how to use contact CRM data in the js part of a custom module.

 

This is a data series for a chart:

 

series: [{
name: 'sales',
data: [30,40,45,50,49,60,70,91,125]
}],

 

How can I replace a static data value with, for example, the value of:

{{ contact.tenancy_created_company }} ? I'm assuming I need to 'set' this value in the HTML/Hubl but I'm struggling to get anywhere.

 

I'd be really grateful for any help!

0 Upvotes
2 Accepted solutions
Kevin-C
Solution
Recognized Expert | Partner
Recognized Expert | Partner

Hey @tommitchell 

 

You might be able to use the tojson filter to output the data needed to a global in the html/hubl. Then with your custom JS, parse and declare it to your object key.

View solution in original post

alyssamwilie
Solution
Recognized Expert

Yes, you would need to declare the data in the HTML/HUBL. Something like:

HTML/HUBL

<script>
  window.data = {
    {{ contact.tenancy_created_company|tojson }}
  }
</script>

JS

series: [{
  name: 'sales',
  data: window.data
}]

If this answer solved your question, please mark it as the solution.

Alyssa Wilie Profile Image

Alyssa Wilie

Web Developer at Lynton

Learn HubL | Get Marketing Insights

Lynton's HubSpot theme Rubric now available. Click to download.

View solution in original post

2 Replies 2
alyssamwilie
Solution
Recognized Expert

Yes, you would need to declare the data in the HTML/HUBL. Something like:

HTML/HUBL

<script>
  window.data = {
    {{ contact.tenancy_created_company|tojson }}
  }
</script>

JS

series: [{
  name: 'sales',
  data: window.data
}]

If this answer solved your question, please mark it as the solution.

Alyssa Wilie Profile Image

Alyssa Wilie

Web Developer at Lynton

Learn HubL | Get Marketing Insights

Lynton's HubSpot theme Rubric now available. Click to download.
Kevin-C
Solution
Recognized Expert | Partner
Recognized Expert | Partner

Hey @tommitchell 

 

You might be able to use the tojson filter to output the data needed to a global in the html/hubl. Then with your custom JS, parse and declare it to your object key.