Use CRM data in JS

SOLVE
Highlighted
Regular 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!

Reply
0 Upvotes
2 Accepted solutions

Accepted Solutions
Advisor

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.

Esteemed Contributor | Diamond Partner

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

Alyssa Wilie

Web Developer at LyntonWeb

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

2 Replies 2
Advisor

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.

Esteemed Contributor | Diamond Partner

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

Alyssa Wilie

Web Developer at LyntonWeb

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