Skip to main content
Version: 11.2

$.udb.currentFrameId

note

This article is about the currentFrameId property of the udb object.

$.udb.currentFrameId

Holds the id of the frame context that is currently, synchronously executing (e.g. 'ApplicationFrame'), or undefined if no specific context is active. It is maintained automatically by the framework: whenever code is run through $.udb.executeInContext() (or through the context machinery that UdbPromise uses internally), currentFrameId is set to that context's id for the duration of that call, and automatically restored to its previous value afterwards.

tip

This property was much more important in USoft 10.1, before promises tracked context automatically. Truly asynchronous code (e.g. a plain setTimeout(), or a native Promise) runs after the synchronous call that set currentFrameId has already finished and restored it, so by the time such a callback fires, currentFrameId has typically reverted to undefined — unless you captured it beforehand and explicitly restored it with $.udb.executeInContext(), as in the pattern shown below.

Now that UdbPromise automatically carries the context of the call that created it through its entire .then()/.catch()/.finally() chain, this manual capture-and-restore dance is rarely necessary anymore. Prefer relying on UdbPromise's automatic context propagation over reading (or setting) currentFrameId directly.

Syntax

$.udb.currentFrameId

Example

$.udb.executeInContext('ApplicationFrame', () => {
console.log($.udb.currentFrameId);
});
> ApplicationFrame

Outside of a context that is currently being executed in this way, the value is undefined:

console.log($.udb.currentFrameId);
> undefined

The USoft 10.1 capture-and-restore pattern

Before UdbPromise existed, code that needed to continue in the same context after a plain asynchronous call (such as setTimeout()) had to capture currentFrameId first, and explicitly restore it afterwards:

let context = $.udb.currentFrameId;
setTimeout(() => {
$.udb.executeInContext(context, () => {
// continues in the original context
});
}, 1000);

A UdbPromise-based equivalent, such as .wait(), preserves context automatically and does not need this pattern:

$.udb.wait(1000).then(() => {
// still in the original context, automatically
});

If you specifically do not want to use promises at all, but still need the context preserved, use udbTimeout() instead of the manual pattern above:

udbTimeout(() => {
// still in the original context, automatically
}, 1000);
warning

Although currentFrameId can technically also be assigned a value directly, this is a low-level internal bookkeeping mechanism: assigning it yourself bypasses the automatic restore that .executeInContext() and UdbPromise normally take care of, and can leave the application in an inconsistent context afterwards. Use $.udb.executeInContext(), or let UdbPromise manage context for you, instead of setting currentFrameId directly.