Skip to Content
avatar image
Former Member

how to retrieve data from calc view using XSJS?

I'm following the this example to retrieve data from the back-end using xsjs but when I run my app I get an empty array as a result and can't figure out why.

example I'm using: XSJS example

here is my code:

var select_all_sales_orders_query = "SELECT * FROM \"_SYS_BIC\".\"MYPATH/CALCULATION\" (\'PLACEHOLDER\'=(\'$IP\', '34963'))"; 

function close(closables) { 

  var closable; var i; for (i = 0; i < closables.length; i++) { 

closable = closables[i]; if(closable) { closable.close(); } 
} } 

function getSalesOrders(){ 

var salesOrdersList = []; var connection = $.db.getConnection(); 

var statement = null; var resultSet = null; try{ 

statement = connection.prepareStatement(select_all_sales_orders_query); 

resultSet = statement.executeQuery(); 

var salesOrder; 

while (resultSet.next()) { 

salesOrder = {}; 

salesOrder.CAGE = resultSet.getString(1); } } 

finally { 

close([resultSet, statement, connection]); } 

return salesOrdersList; } 

function doGet() { 

try{ 

$.response.contentType = "application/json"; 

$.response.setBody(JSON.stringify(getSalesOrders())); 

} catch(err){ 

$.response.contentType = "text/plain"; 

$.response.setBody("Error while executing query: [" + err.message + "]"); $.response.returnCode = 200; } } doGet();

I'm trying to retrieve a single column for now to test it but the result is simple this '[]'. I'm new to XSJS so I don't know how to debug it. I tried using $.trace.debug('message'); but this doesn't print anything on the console. Can someone show me how to debug this or shine some light on what I'm doing wrong?

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Jun 15, 2017 at 05:23 PM

    The way you address the parameter of your calc view is incorrect. Instead of '\n$IP' it must be '\n$$IP$$' (if the parameter name is IP).

    Regarding the debugging question, you can do a search here or in the official documentation. There are already many posts available. If you are working with the web-based dev workbench it is pretty easy. A search in the documentation would produce a result like Tutorial: Create and Debug a Server-side JavaScript Application.

    Regards,
    Florian

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      I got it fixed. Smart me forgot to include the line salesOrders.push(salesOrder); which in turn was just returning the empty array salesOrders. So it was just a mistake on my side. Thanks for your help though.