Skip to Content
0

how to retrieve data from calc view using XSJS?

Jun 15, 2017 at 03:41 PM

163

avatar image
Former Member

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?

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Florian Pfeffer
Jun 15, 2017 at 05:23 PM
0

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

Show 3 Share
10 |10000 characters needed characters left characters exceeded
Former Member

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.

0

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

0
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.

0