Javascript Variable Question

I have this piece of Javascript I’m using from OrgChartJS

 var chart = new OrgChart(document.getElementById("tree"), {
            nodeBinding: {
                field_0: "name"
            nodes: [
                { id: 1, name: "Amber McKenzie" },
                { id: 2, pid: 1, name: "Ava Field" },
                { id: 3, pid: 1, name: "Peter Stevens" }  

The code as you see it here works great in my app.

To use it with my own data, I have a workflow that generates an array in the format they require, the output looks something like this.

id: 378, pid : 341, name: “Alessia White”, title: “Human Resources Business Partner”, img: “”}

If I paste my output direclty into the function, it works. However my output is stored in a Variable or Returned from the Loop generating the data itself, so I need to pass that into the Javascript. I am trying to pass the data stored, but the function will not work. Here is a snippet of code, any idea what I’m doing wrong here?

var chart = new

OrgChart(document.getElementById("tree"), {
    mouseScrool: OrgChart.action.none,
    nodeBinding: {
        field_0: "name",
        field_1: "title",
        img_0: "img"
    enableDragDrop: false,
    nodes: [ 

Where are you using this code (javascript action, script tag in html, script tag in page head)?
What is the error you get in the console?

You should try to use the code in a javascript action.

No errors in the Javascript console. I’m using it inside of an HTML element.

If I use it inside of a regular Javascript action, how would I get the code to print to the page?

@dorilama I did some more testing here, I think I may see what’s going on.

In Chrome when I print out the array I’m trying to pass I see that the variable test which I am assigning to one part of the array, has leading and ending quotations ("), so I don’t believe it’s being read-in correctly.

You’ll also see in my array, it looks like it’s storing it as a string which I suppose is not the expected format. Any idea how to correct this?

Here is code I am using to generate the string to be stored in the array.


I think what you want to store is an Object, not a string. Can you try by removing the quote on your formula?

That did not work, but what did was passing Object. Here is the output I used to get this to work.


Trying to push this data to Xano is a whole different challenge though, trying to find some documentation as Arrays are not simple to get into there.

Your screenshots show that you are very confused about what you are doing.
You are using an html element and executing javascript in the binding function.
It’s probably better if you just use javascript actions in a workflow.

It actually is working great now :slight_smile: