Problem accessing app model new object after calling BF namedAction

I’m facing an intermittent issue where app.subDesigns remains undefined even after calling BF.namedAction('loadDesigns').

The odd thing is:

I can see subDesigns populated in the dev tools, which means that loadDesigns did complete and returned data, but in js, it stays undefined or empty** at runtime.

Here’s the polling logic I’m using to wait for it:

BF.namedAction(‘loadDesigns’);

(async () => {
let maxTries = 500;
let interval = 200;

while ((!app.subDesigns || app.subDesigns.length === 0) && maxTries-- > 0) {
console.log(‘Waiting’);
await new Promise(resolve => setTimeout(resolve, interval));
}

if (app.subDesigns) {
console.log(‘Loaded:’, app.subDesigns);
} else {
console.log(‘Timed out waiting for app.subDesigns’);
}
})();

If you are seeing it populate and later change, then that points to something else erasing the app.
Do you have any appSyncing or caching enabled?

It actually stays populated, when viewing in dev tools, but when accessing using js app.subDesigns stays consistently undefined. On refreshing page, it randomly works

Probably not ‘random’ :wink:
In your JS, you may not have ‘app’ context. maybe review that.

is there a reason you are using a Immediately Invoked Async Function Expression (IIAFE) function?
they are designed to isolate scope …

Perhaps if you tell us what you are wanting to di in that timing look we could suggest the proper bet practice.