getData()

Serialize the component data from the specified component instance into a string with JSON content.

Return = ComponentInstance.getData();

Example: var vData = this.getInstance().getData();

Arguments

None

Return Value

Returns an object that is serializable to JSON, which contains the current component data, and metadata properties.

Description

The getData() function is especially useful for mobile applications when connection to the server is not available. It enables you extract the data from a DSP instance so that you can store it locally using the uniface.datastore APIs. It can then be reloaded into a component instance whenever required, either for read-only purposes, or to upload the data to the server when a connection is possible.

Using getData()

A DSP contains the following data, in which items 1,2, and 3 were retrieved from the database and item 4 was added using uniface.Occurrence.insertNewBefore().

SONGS_DSP

SONGS_DSP with four items

Use getData() to put this into a JSON stream vData:

var vData = this.getInstance().getData();

The resulting JSON document contains both the data and their reconnection properties, indicating the status of each data object. You can then use the uniface.datastore.put() function to write this data to local storage:

uniface.datastore.put({
  _id: 'songs_dsp',
  title: vData
 }).then(function (response) {
  doc = vData;
  console.log(doc);
 }).catch(function (err) {
  console.log(err);
 });
Version Change
9.7.03 G304

10.02.01

Introduced

Related Topics