Help with app connect parsing and javascript

Tying to finish what i hoped would be a one day project before heading off on holiday. Risked coming out of my comfort zone at server level into app connect.

Hit a roadblock right at the end

So here is a scenario (simplified)

I have .js code like this:

const id = 'ID_3;
const parent='PA_2";
const index = 2;

On the content page i have a variable

to which i want to assign an object from the javascript

 const DataObject = {
                    id: id,
                    parent:parent,
                    index: index
                };

so i have tried this (and a few other variations

 const DataObject = {
                    id: id,
                    parent:parent,
                    index: index
                };
                const DataString = JSON.stringify(DataObject);
                const newData = JSON.parse(DataString);
                dmx.parse(mydata.setValue(newData)");

when run, i see in the console for dmx.app.data.content.mydata

{
    "$type": "value",
    "value": null
}

I was expecting to see an object

{"id":"ID_3","parent":"PA_2","index":2}

i want to be able to address the function output with
mydate.id, mydate.parent and mydata.index

Anyone see where i am going wrong?

Should be:

const id = 'ID_3';  // Missing closing quote in original code
const parent = "PA_2";  // Wrong quote type used
const index = 2;

The quotation mark at the end of this line is misplaced

LOL, thanks ben, sadlty that was an posting error introduced in trasposing the simplified code.

I am now getting the json being added to the app conenct variable with code like this:

const jsonDataObject = {
                    id: draggedCard.id,
                    parent: newParent.id,
                    index: newIndex
                };
               jsonDataString = JSON.stringify(jsonDataObject);;
                const component = dmx.app.find('mydata');
                if (component) {
                    component.set('value', jsonDataObject);
                } else {
                    console.warn('component mydata not found in app');
                }

This appears to work and i can see the object in dmx.app.data

image

And i have literally just solved this when typing this post by the following app connect references

mydata.value.id
mydata.value.parent
mydata.value.index

Whoo Hoo!

1 Like