Please refer to the source code of this page for boilerplates (F12 for console).

Wiring up



Notes:
jQuery is required and should be included before the tEcs library (for ajax requests).
It is recommended to add local fallback version of the library if use use it in production (click "download" on the right).
We bear no responsibility for possible reachability interruption of directly linked components, they are useful to cold start your project and set up testing.

Core APIs

tEcs.executeXql()

Example:
{
    data: "SELECT TOP 10 MATNR, MAKTX FROM MAKT"
}



tEcs.executeFunction()

Example:
{
    name: 'Z_ECS_GET_STOCK_INFO',
    data: {
        exports: {
            MATNR: '100-100'
        }
    }
}



tEcs.executeInScope()

Example (same for two functions):
{
    functions: [
        {
            name: "Z_PREPARE_REQ",
            data: {
                PARAMONE: "SOMEVALUE"
            }
        },
        {
            name: "Z_EXEC_REQ",
            data: function(){
                return parametersSapCheck;
            }
        }
    ]
}

No Live Demo :(


Config

"connection" parameter should be passed to each of the above functions!
For ECS on premise this parameter is optional and tEcs will be working with defaults out of the box.
var connection = {
    ecs: {
        //authenticate: "Basic XXX",
        core: true,
        coreApiKey: "Y39j",
        //instance: "ec2",
        url: "https://[namespace].servicebus.windows.net/ecs/ws"
    }
};
Optionally "done" and "fail" handlers could be passed to execute custom actions with result or error.
{
    connection: connection,
    done: function(data) {
        alert('Everything as planned!');
    },
    fail: function(data) {
        alert('Something broke :(');
    }
};
Full example of call executeFunction():
tEcs.executeFunction({
    connection: {
        ecs: {
            core: true,
            coreApiKey: "Y39j",
            instance: "ec4",
            url: "https://ecscore.mydomain.com"
        }
    },
    data: {
        exports: {
            MATNR: '100-100'
        }
    },
    done: function(data) {
        alert('Everything as planned!');
    },
    fail: function(data) {
        alert('Something broke :(');
    },
    name: 'Z_ECS_GET_STOCKS'
});
Full example of call executeInScope():
var FUNCTION_TWO_PARAMETERS = {
    exports: {
        PARAMX: 'VALX'
    }
};

tEcs.executeInScope({
    // out of the box commit will be added after given functions
    // commit: true,
    connection: {
        ecs: {
            //authenticate: "Basic Y39j",
            core: true,
            coreApiKey: "Y39j",
            instance: "ec4",
            url: "https://ecscore.mydomain.com"
        }
    },
    // these "done" and "fail" will be executed when all functions are executed
    done: function(data) {
        alert('All funcitons executed!');
    },
    fail: function(data) {
        alert('Something broke :(');
    },
    functions: [
        {
            name: "FUNCTION_ONE",
            data: {
                PARAMONE: "SOMEVALUE"
            },
            // SET VALUES FOR THE NEXT FUNCTION
            done: function(data){
                // updating parameters of next function!
                FUNCTION_TWO_PARAMETERS.exports.PARAMTWO = data.imports.PARAMY;
            }
        },
        {
            name: "FUNCTION_TWO",
            // note, data is a function!
            data: function(){
                return FUNCTION_TWO_PARAMETERS;
            }
        }
    ],
});

Helper APIs

tEcs.getLastError()

Example:
$.ajax({
    url: 'http://somenonexistenturl.com'
}).fail(function() {
    console.log(tEcs.getLastError());
});
or
tEcs.executeFunction({
    name: "Z_ECS_GET_STOCK_INFO"
});


Summing up

Extended logging and error handling: parsing/unwrapping of XHR, ECSCore responses.
Out of the box functionality with minimum parameters.
No configuration needed.

Changelog.

4.1

Added "coreApiKey" field to use with new Api-Mechanism (ECSCore-APIKEY header)