Use CRM data in JS

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!

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.

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
}]