-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample_2.xsjs
47 lines (38 loc) · 1.23 KB
/
example_2.xsjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// import DataTable Server-Side Processing library
var dataTable = $.import("your.package.name", "DataTable");
// or
// var dataTable = $.import("/your/package/name/DataTable.xsjslib");
// connect to Hana
var conn = $.db.getConnection();
app.setSchema(conn, 'MY_SCHEMA');
var output = {};
try {
var tableName = 'MY_TABLE';
dataTable.setOptions({
additionalFilters: [
{col: 'CLIENT_ID', operator: '=', value: 1234},
...
],
columnFormatter: {
'DT_SALES': function(dbValue){
// implement date parsing...
},
'TOTAL_SALES': function(dbValue){
return 'US$ '+ dbValue;
}
},
});
// execute queries and retrieve output parameters expected by DataTable
output = dataTable.process(conn, tableName);
$.response.status = $.net.http.OK;
$.response.contentType = "application/json";
$.response.setBody(JSON.stringify(output));
} catch(e) {
output = "Exception "+ JSON.stringify(e);
$.response.status = $.net.http.INTERNAL_SERVER_ERROR;
$.response.contentType = "plain/text";
$.response.setBody( output );
} finally {
// close connection to Hana
conn.close();
}