Client-side Data Cache Actions

 Action Javascript

Action Javascript allows you to perform several actions on data items in the Data Cache. Select the 'Client-side Data Cache Actions' action from the list of available actions.

Then in the editor, select the action type:

The actions currently currently supported are:

Refresh Data Items(s)

allows you to refresh one or more data item. You can also select to refresh all items. Refreshing data cache items is an asynchronous action. The action allows you to specify an onComplete action that will be called after all items have been refreshed.

Read Data

allows you to read the data in a data item. Reading a data item is an asynchronous action. You can specify the Javascript to run once the item has been read. If you read an item that has been set to Delay query until explicit refresh and the item has not yet been refreshed, the item will be automatically refreshed first, and then it will be read. Once it has been read the onSuccess Javascript event is fired and the data in the data item is available to your Javascript code in the data variable. You can specify an optional Filter and Order property to filter/sort the data in the data array before the onSuccess event handler is called.

 Read Data Action

The builder for the Read Data action is shown below. You specify the name of the data item you want to read and then you define the Javascript code you want to execute once the item has been read. You code can reference data - a Javascript array that contains the data in the data item.

The filter allows you to define an arbitrary filter to filter the data. The filter builder dialog is shown below. The filter is in the form of a Javascript expression that evaluates to true or false. Fields in the data item are referenced with the data. prefix. In the screenshot shown below only records in London or Berlin are included in the data array passed to the onSuccess event handler.

The order allows you to define an arbitrary sort order for the data in the data array. The order builder is shown below:

The order builder allows you to define a multi-level sort. It also allows you to parse numeric, logical and data strings into data of the correct type so that the data are ordered correctly. For example data values in your data cache might be in form of date strings (e.g. 12-31-2015). In order to sort these values correctly, they have to first be parsed into real date objects.

 Data Cache Methods

The UX object has several methods for working with data items.

  •  {dialog.object}.refreshDataCacheItem(listOfItemsToRefresh, onCompleteFunction)

    {dialog.object}.refreshDataCacheItem refreshes a Data-cache item. Parameters are listed below:

    listOfItemsToRefresh

    A comma delimited list of data items to refresh or '*all' to refresh all items.

    onCompleteFunction

    A function to call when all of the data items have been refreshed. Data items are refreshed asynchronously.

  •  {dialog.object}.getFromDataCache(itemName,onSuccessFunction, onFailFunction, filter, order)

    {dialog.object}.getFromDataCache reads a Data-cache item. Parameters are listed below:

    itemName

    The name of the data item to read

    onSuccessFunction

    The Javascript code to execute once the data item has been read. Reading data items is asynchronous. Your Javascript can reference data, an array with the data for the specified data item.

    onFailFunction

    The Javascript code to execute if there was an error reading the data item.

    filter

    A string (with a filter expression) or a function that defines how the data should be filtered.

    order

    An object that defines how sorting should be performed, or a function that defines a custom order definition.

  • Here is an example of the filter parameter specified as a string:

    var _filter = 'data.Country == "USA" || data.Country = "France"';
  • Here is an example of the filter parameter specified as a function:

    var _filter = function(data) {
    if(data.City == 'Boston') return true;
        else return false;
    }
  • Here are examples of the order parameter specified as an object:

    //sort by City, then by Lastname (descending)
    var _order = {'City' : 1, 'Lastname': -1};
    
    //sort a date string that is in the format MM-dd-yyyy
    var _order = {'DateOfBirty:date:MM-dd-yyyy' : 1);
  • Here are examples of the order parameter specified as an function:

    //sorts by Lastname, then by DOB ( a date field with a format of MM-dd-yyyy) in descending order
    
    var _order = function(a,b) {
        if(a.Lastname > b.Lastname) return 1;
        else if(a.Lastname < b.Lastname) return -1;
        else {
            if(new Date().fromFormat(a.DOB:date:MM-dd-yyyy,'') > new Date().fromFormat(b.DOB:date:MM-dd-yyyy,'')) return 1;
            else return -1;
       }
    }

See Also