Generic Javascript API Access to backend: Execute Function

Execute Function: How to call the application backend from javascript

During front-end development, we normally run into situations where we need information from the backend or we need some functionality that is already implemented there with all the necessary logic.

Obviously, this where javascript AJAX comes into play and we launch a call to the backend to retrieve the information or operations that we need.

There are mostly three ways to do this:

We can call the ExecuteFunctions API through the Utilities module, like this:

var url = "module=Utilities&action=UtilitiesAjax&file=ExecuteFunctions";
var url = url + "&functiontocall=getModuleWebseriviceID&wsmodule=Accounts";
fetch('index.php?'+ url, {
	credentials: 'same-origin'
}).then(function(response) {
	return response.text();
}).then(function(data) {
	console.log('Accounts webservice ID is: ' + data);
});

Which in my chrome developer console, sending the request to the coreBOSTest database, looks like this:

We also have a generic javascript funtions which avoids from having to type the whole AJAX call. Using this function the above example would be:

ExecuteFunctions('getModuleWebseriviceID','wsmodule=Accounts').then(function(data) {
	console.log('Accounts webservice ID is: ' + data);
});

Which is MUCH NICER!

In the chrome developer console this looks like this:

We enhance the list of supported actions in ExecuteFunctions regularly so have a look at the latest copy to see all the things that can be done and don't hesitate to ask if you find something missing that you think should be there.

This is the list of actions that can be found: