Child pages
  • Online Mobile

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

From Servoy 7.3 onwards a Servoy developer can do a remote search for a specific foundset being in find mode and has some findstates applied.findstates applied.

This allows to work with live data on the server, like foundsets with a million records.

Concept

The Servoy find/search concept is extended to start with a local find and utilize a server side search.

Usage client side

In the mobile solution you set a foundset into find mode and then add some criteria then instead of calling search() on the foundset, call remoteSearch on the mobile plugin:

Code Block
if (foundset.find());
{
	foundset.anumbervalue = ">10";
	plugins.mobile.remoteSearch(foundset,successCallback,errorCallback);
}

 

The successCallback and errorCallback params are functions that are called when this remoteSearch is done because this call is an a-synchronize call to the server. After this you can block the user or let the user go on.If the user can go on in its solution it is recommended that the foundset that is in remote search mode, is not a foundset of the current ui

On success the retrieved foundset as argument is not the same foundset started the find() on, but a new one that is get similar to the one from databaseManager.getFoundSet(); This way the ui is not touched by the remoteSearch itself.

This new foundset should be loaded into the UI by the success function as shown below. Note: returning a new foundset is intentionally to prevent remote search result to touch the UI.

The success and error callbacks have the following signature:

Code Block
/**
 * @param {JSFoundSet} the foundset that was given to remoteSearch
 */
function sucessCallback(foundset) 
{
   if (foundset.getSize() >0) {
     // something found on the server show it in the current form
	controller.showRecords(foundset);
   }
}
/**
 * @param {Number} statusCode The http status code 
 * @param {String} message The message of the error
 * @param {JSFoundSet} foundset The foundset that was givenpassed to remoteSearch
 */
function errorCallback(statusCode, message, foundset) 
{
	//do what ever is needed, like showing alert
}

 

Needs server side

The plugins.mobile.remoteSearch() will call the service solutions 'offline_data' form 'ws_create()' method with the following signature:

 

Code Block
/**
 * @param data The data that the client send over in the body 
 * @param version The version number of this request
 * @param method What kind of create must be done 
 * @param authenticateResult Object that is created in the ws_authenticate method.
 */
function ws_create(data,version,method,authenticateResult) 
{
	// Test if it is a remoteSearch call
	if (method == "search") {
		// Create the FoundSet from the data that is send over from the mobile client
		var fs = plugins.mobileservice.createRemoteSearchFoundSet(data);
		// This FoundSet is in find mode, more stuff could be added to it if you want to filter even more. Then call search()
		fs.search();
		// Create the OfflineDataDescription that will be returned for this remoteSearch
		var retval = plugins.mobileservice.createOfflineDataDescription('data_');
		if (fs.getDataSource() == "db:/server/test") {
			// if this was a foundset on the test table, traverse only the relation of "test_to_test2". 
			var traverse = new Array();
			traverse[0] = "test_to_test2";
			retval.addFoundSet(fs,traverse);
		}
		else {
			// for all other datasources just call addFoundSet which will traverse over all relations found in the mobile shared module when encountered in the records of this foundset.
			retval.addFoundSet(fs);
		}
		return retval;
	}
}

 

That This method is called by the remoteSearch call on from the client and the OfflineDataDescription object that is returned will be merged into the current synchronized synced set the mobile client already has.

For all the pk's that are returned the service solution will be ask for to get the latest data for the Record.

If that record is changed on the client, the record data that the client had will be kept, to not delete changes the client made to it. If that is not the case then the local storage is updated with the new record data.

When everything is made up to date in the client, the foundset that was given The foundset passed to remote search will go out of find mode and the remote filtered foundset will be given to the successCallback function.

Al All other Globalglobal/Shared shared foundsets will have all the new records and the existing records loaded, related foundset will be exactly the pk set that the server did return for it.

Except new records on the client side, those will be inserted back in.

This does result in that the set of data in the mobile client does grow with every remoteSearch() call that gets new records, so calling clearData() or with loadData() or doing a full sync() at certain times is recommended.

...