26
Views
3
Comments
Solved
Best method to convert a list into javascript array

Hi OS community, 

I have a list of dates/events i want to pass to a highcharts timeline (similar to this).

I have a list of event structures {x, name, label, description} and some custom JS firing to display the chart.

What is the best way to pass the list into the data array in the JS? I have attempted to create a text variable with the data and insert that as a parameter into the JS but i suspect it is being handled as text (i have also used eval() to attempt to bypass this). 

Is there a way around this?   

mvp_badge
MVP
Rank: #78
Solution

Hi Robert,

If I understood the case correctly, I would suggest the below steps 

Steps to follow:

1) Create a Structure with required attributes. Let's call it ChartData

2) Create a Local Variable of ChartData List Type. Let's name it DataList

3) Use the JSONSerialize  action flow node to serialize the list of records i.e DataList to convert it into array of JSON objects

4) Create an input parameter of Text data type to the JS node and map the same serialized JSON output value (point 3) to it.


Hope this helps you!


Kind regards,

Benjith Sam

Rank: #9775

Thanks Benjith, that worked well, only i had to wrap the text in JSON.parse().


Thanks again

Rob