Initializing help system before first use

# The Promise API

Some methods in the JavaScript API return an instance of the Promise object

This is a global object exposed within the browser. Some browsers do not currently support it as its part of the next version of JavaScript, known as ECMAScript 6. For those browsers we include a library which emulates the Promise object very closely so there should be no difference.

Promises are returned from JavaScript API methods that involve some asynchronous process, such as fetching or sending data over the network. The JavaScript API documentation shows which calls return promises and what each promise resolves to. This is in the following format:

    Promise.<User>

This example shows that User is the type of object that the promise resolves to.

A promise is returned when the return value of a method is not immediately available. It allows your code and the browser to continue with other tasks until that value is available. Given a promise object you can attach functions to be called when it resolves or if it fails. You can also collect a number of promises and chain them or call a function once they have all resolved or if one fails. The methods available on a promise are:

    promise.then(function(value) {
       // This function is invoked when the promise has
       // 'resolved' and the first argument passed in will
       // be the return value from the call made, if there is one.
    }).catch(function(error) {
       // You can chain the "then" and "catch" calls on a promise
       // The first argument passed into catch will be an Error
       // object explaining the error that occurred
    });

As you can see there are only two methods on a promise object, `then` and `catch`. They can be chained and you can also return a new value from a `then` or `catch` function that will be wrapped in a promise and sent on to the next in the chain.

Once a promise is resolved or rejected it will never change, it will only be settled once.

There are some static methods available on the Promise object. One particularly useful one is `Promise.all()`. This takes an array of promises that you have captured and will return a new promise that settles when all the promises resolve or if one of them is rejected. For example:

    var tasks = [
       view.getUser(),
       view.getScenarioProperties(0),
       view.start()
    ];
    Promise.all(tasks).then(function(values) {
       // The resolved values are available in an array passed as the
       // first argument, in the same order as that defined
       // in the "tasks" array.
       var user = values[0];
       var scenarioProperties = values[1];
    }).catch(function(error) {
       console.error('could not start view. Reason: ' +
            error.message);
    });

Parent Topic Using the JavaScript API to Create Custom Views

© 2001-2026 Fair Isaac Corporation. All rights reserved. This documentation is the property of Fair Isaac Corporation (“FICO”). Receipt or possession of this documentation does not convey rights to disclose, reproduce, make derivative works, use, or allow others to use it except solely for internal evaluation purposes to determine whether to purchase a license to the software described in this documentation, or as otherwise set forth in a written software license agreement between you and FICO (or a FICO affiliate). Use of this documentation and the software described in it must conform strictly to the foregoing permitted uses, and no other use is permitted.