cancel
Showing results for 
Search instead for 
Did you mean: 

how to retrieve data from calc view using XSJS?

Former Member
0 Kudos

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?

Accepted Solutions (0)

Answers (1)

Answers (1)

pfefferf
Active Contributor
0 Kudos

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

Former Member
0 Kudos

I made a typo when posting the question. Actually I have \'$$IP$$'. I tried it your way but I get an error saying that the input $$IP$$ is not defined.

pfefferf
Active Contributor
0 Kudos

Can you post the error and the definition of your parameter in the calc. view?

Former Member
0 Kudos

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.