RestCollectionBase Common Parameters

The RestCollectionBase objects are automatically created by the Finesse JavaScript Library when applicable APIs are used. Thus, the RestCollectionBase objects do not have to be initialized manually. The RestCollectionBase class extends the RestBase and supports all the handlers of RestBase.

The RestCollectionBase extends RestBase class. Hence, all the common parameters of the RestBase applies to RestCollectionBase.

Fields borrowed from class finesse.restservices.RestBase: ajaxRequestTimeout, restResponseStatus.

Methods borrowed from class finesse.restservices.RestCollectionBase: getCollection, refresh.

Methods borrowed from class finesse.restservices.RestBase: addHandler, getData, getId, getProperty, hasProperty, isLoaded, removeHandler.

Example of Common Configurations

Code Snippet
Copy_user.getDialogs(options) // User REST API Object is composed of Dialogs Collection Object.
_team.getUsers(options) // Team REST API Object is composed of a Users Collection Object.(Users who are the part of that team)
_user.getMediaList(options) // User REST API Object is composed of MediaList Collection Object.
_user.getQueues(options) // User REST API Object is composed of Queues Collection Object.
_team.getTeamMessages(options) // Team REST API Object is composed of a TeamMessages Collection Object.
ParameterDescriptionExample
onLoad

A callback that is invoked one time in the life of the object, which is when the initialization is successful and the data is loaded into the JavaScript object successfully. This JavaScript object is then passed to the handler as a parameter.

This is equivalent to the success handler of a GET REST API request.

An example, on User load which lists all the associated Dialogs in a grid:

Code Snippet
Copyuser.getDialogs({
    onLoad: function(dialogs){
        // successfully loaded the dialogs collection object, now format and display in the grid
        var dialogCollection = dialogs.getCollection();
        for(dialogId in dialogCollection){
            if(dialogCollection[dialogId] instanceOf finesse.restservices.Dialog){
                // each item in the Dialogs Collection will be an instance of Dialog object.
                // can format and display each record here.
            }
        }
    }
});
onCollectionAdd

A callback that is invoked when a new object is added to the collection. The newly added object is then passed to the handler as a parameter.

An example, on User load which lists all the associated Dialogs in a grid, and updates them as and when a new Dialog is added:

Code Snippet
Copyuser.getDialogs({
    onLoad: function(dialogs){},
    onCollectionAdd: function(dialog){
        // called when a new Dialog is added to the collection
        // add this new dialog to the Grid
    }
});
onCollectionDelete

A callback that is invoked when an object is removed from the collection. The removed object is then passed to the handler as a parameter.

An example, on User load which lists all the associated Dialogs in a grid, and updates them as and when a new Dialog is removed:

Code Snippet
Copyuser.getDialogs({
    onLoad: function(dialogs){},
    onCollectionDelete: function(dialog){
        // called when a new Dialog is removed from the collection
        // remove this dialog from the Grid
    }
});
onError

A callback that is invoked with the response object as the parameter when any of the operations such as, GET, PUT, POST and DELETE fails.

For more information on parameters, see RestBase Common Parameters.

An example when the operations fail:

Code Snippet
Copyuser.getDialogs({
    onLoad: function(user){},
    onError: function(rsp){
        // log the error message to clientLogs with rsp.error.errorMessage
        // render a meaningful error message into the UI
    }
});