Child pages
  • Online Mobile
Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Next »

From Servoy 7.3 a developer can do a remote search for a specific foundset that is set in find mode and has some findstates set.

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:

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, but a new one that is get from databaseManager.getFoundSet(); This way the ui is not touched by the remoteSearch itself.

The success and error callbacks have the following signature

/**
 * @param {JSFoundSet} the foundset that was given to remoteSearch
 */
function sucessCallback(foundset) {
   if (foundset.getSize() >0) {
     // something found on the server.
   }
}
/**
 * @param {Number} statusCode The http status code 
 * @param {String} message The message of the error
 * @param {JSFoundSet} foundset The foundset that was given to remoteSearch
 */
function errorCallback(statusCode, message, foundset) {
}

 

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

 

/**
 * @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 method is called by the remoteSearch call on the client and the OfflineDataDescription object that is returned will be merged into the current synchronized set the 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 to remote search will go out of find mode and the filtered foundset will be given to the successCallback function.

Al other Global/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 doing a full sync() at certain times is recommended.

 


  • No labels