.executeInContext()

Previous Next

Switches the default context of a function call. Use this function if there is a need to cross the boundaries of context, for example,

If you are using .then() to take a next step if a promise is fulfilled, but in that next step, you want to refer back to the context of the previous step (.then() gives up that context by default). See Example.

a VariableSet data source on one page must be accessed by controls on a different page.

Returns the result of executing the function func. This could be a result value, or a Promise that yields a result value.

Syntax

.executeInContext( contextfunc )

The required context refers to the root context if it has the value "" (empty string). A subpage within the root context is referred to by the name of the page. In context, names of pages contained in pages are separated from the name of the containing page by a forward slash:

$.udb.executeInContext("MyPage/SubPage", function() { … });

The required func is the function call for which the default context is being switched.

Example

In this example, .executeInContext() is necessary because, otherwise, the context of the query (including its search condition values) is given up if and when you enter the .then() branch:

$.udb('TOUR').executeQuery().then(function(dsc){
  var searchCols = {};  
  dsc.searchCols().each(function(index,col){
      searchCols[col.name()] = col.val();
  });
  $.udb.executeInContext( dsc.context, function(){
    $.udb.navigateTo("Tours Info 1.2 Results").then(function(){
      $.udb('TOUR').searchCols().each(function(index,col){
        col.val(searchCols[col.name()]);
      });
    });
  });
});

 

See also

.getContext()