The following code example from a SharePoint application page shows how the first ten records of SAP table MAKT are read, using an XtractQL query within JavaScript with AJAX:
Javascript.
$(document).ready(function () {
var q = 'SELECT TOP 10 * FROM MAKT';
$.getJSON('/_vti_bin/ERPConnectServiceRest.svc/ExecuteXQL?q=' + q,
function (data) {
// TODO: Handle JSON response!
});
The ExecuteXQL operation of the ERPConnectServiceRest.svc Web service returns a JSON object. AJAX is enabled through the $.getJSON-method of jQuery (see www.jquery.com).
JSON is an acronym for JavaScript Object Notation and is a lightweight data exchange format. For the development with jQuery and the use of AJAX, the web debugger tool Fiddler2 (www.fiddler2.com) can be very useful:
Result as XML
In addition to returning data JSON format, you can request the data to be returned as XML:
Javascript
$.ajax({
type: 'POST',
url: '/_vti_bin/ERPConnectServiceRest.svc/ExecuteXQLAsXml',
data: '"http://www.theobald-software.com/ERPConnectServices\">
' + q + '',
processData: false,
dataType: "xml",
contentType: 'text/xml; charset=utf-8',
success: function (xml) {
alert($(xml).text());
}
});
Use of a specific ECS Application
If the program should access a specific ERPConnect Services Application, please use the parameter applicationName.
Javascript
$(document).ready(function () {
var q = 'SELECT TOP 10 * FROM MAKT';
$.getJSON('/_vti_bin/ERPConnectServiceRest.svc/ExecuteXQL?applicationName=ECC&q=' + q,
function (data) {
// TODO: Handle JSON response!
});
Return Value
Using the REST interface each XQL statement must return a table as a result. More than one return parameters are not supported. For the execute statement a @RETVAL parameter must be defined.
Example with RESTClient
RESTClient is an add-on for many browsers that enables you to call REST Services. The following screenshot shows how to execute an XtractQL statement using the ECS REST services.