Child pages
  • Developing the Mobile Service Solution

Versions Compared

Key

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

...

Code Block
var retval = plugins.mobileservice.createOfflineDataDescription('data_');

Note: the argument is optional and is used to call rest endpoints for row data at forms starting with this prefix

 

The next step is determining what related data should be traversed and sent to the client. By default (since Servoy 7.2) any relations that exist in a "Mobile Shared Module" attached to the "Mobile Service Solution" will be included in the traversal.

...

Code Block
retval.addFoundSet(fs_contact, traverse);
return retval;

Basically addFoundSet in the service solution exposes an unrelated foundset to the mobile client, which can be used in an unrelated way like in a (first) form or databaseManager.getFoundset(...)
For each record in the provided (unrelated) foundset the specified relations are traversed and all data taken.

...

Code Block
var authenticate_info = questionParams.ws_authenticate[0];
globals.username = authenticate_info.username;

Here the authenticate username is put into a global variable which in turn can be used like:

Code Block
//prepare personal data
var fs_contact = globals.contact_data$username; //global related foundset using username global var, containing the to account manager contact record

Full ws_read method for personalized data.

Code Block
function ws_read(version,name) {
	var questionParams = arguments[arguments.length-1];

	//create return value
	var retval = plugins.mobileservice.createOfflineDataDescription('data_');

	//setting the key for user_select relation
	var authenticate_info = questionParams.ws_authenticate[0];
	globals.username = authenticate_info.username;

	//prepare personal data
	var fs_contact = globals.contact_data$username; //global related foundset using username global var, containing the to account manager contact record

	var traverse = [
		'accountmanager_to_companies',
		'companies_to_contacts'
	]

	retval.addFoundSet(fs_contact, traverse);
	return retval;
}

Providing/Retrieving Entity(=table) Row Data

...

Code Block
function ws_read(version, method) {
	var questionParams = arguments[arguments.length-1];

	if (method == 'list') {
		/** @type {String} */
		var ids = questionParams.ids[0];
		if (ids != null && ids != '') {
			var idsa = ids.split(',', -1);
			if (idsa.length > 0) {
				var json = plugins.mobileservice.getRowDescriptions(foundset.getDataSource(), idsa)
				return json;
			}
		}
	}

	throw 404;
}

TIP: since ws_read for entities is likely the same, it might be beneficial to create a base form containing this logic and extend from this form

...