Timing issue with data detail select with AC2

Ran into this issue while updating an app to AC2. We have a lot of custom JS libraries and code which make use of the dmx object to get things done.

We have a setup when on click of an element inside a custom JS component (not AC2 component), I need to select that ID in a data detail.
The code looks something like this:

dmx.parse("content.dataDetail1.select('" + myvar1 + "')");
somefunction(dmx.app.data.content.dataDetail1.data.start_time);

With AC1, this was working fine. But with AC2, I get an error in console saying cannot read start_time. If I add a setTimeout around the second line with 300ms, it works fine.

300ms is just a random delay which works on one system, might easily break for other users and systems. How can I ensure that the value has been selected in data detail, reliably, so that I can execute the steps below it?

Update:
Just encountered same issue in inline-flow on page as well.
In the flow, first step is dd1.select, and next step uses the value from dd1.data.prop1 - which is resulting in null.

Have updated the title of the issue as this issue does not seem to be confined to JS.

AC2 is too fast I guess...

Not familiar with async and promises but played for 10' with it.
Something like that would work?

async function getDataDetail() {
  let myPromise = new Promise(function(resolve, reject) {
    resolve(getStartTime());
  });
  myStartTime = await myPromise;
}

getDataDetail();

function getStartTime() {
  return dmx.app.data.content.dataDetail1.data.start_time;
}

Too slow in this case actually.
DataDetail returns values in data property, after something has been selected. In my case, after the select step, when I am trying to read the data property, it has not been set yet.

yeah...
The way you describe it, it seems that there is a tiny "gap" between selecting a DataDetail rec and actually manipulating its content/attributes

But if there is a gap in that case, a few other cases comes to mind that will need more attention also...
I have no AC2 for now so I can't play actually with it :disappointed:

@patrick Requesting a resolution for this. This has put a hold on our migration plans from AC1 to AC2.

Bump. Any update on this?

Try following update:

dmxDataTraversal.zip (5.2 KB)

1 Like

This seems to be working well. Thank you. :slight_smile:
Took some time to test it since I got into another issue. Not sure yet if related to AC2. Will create another post if it is.

Fixed in the latest extensions updates.