Skip to Content
0

how to call a calc view with multiple inputs on xsjs?

Jun 16, 2017 at 07:08 PM

135

avatar image
Former Member

I have an xsjs file where I want to call a calc view with multiple parameters but my query doesn't seem to work. I've tried a calc view with a single parameter and it works, but now I have to do it with multiple parameters and my query isn't working but I'm not sure how to structure it properly. I get an error saying "error while executing query". Here is my code.

function close(closables) { 

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

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

function getSalesOrders(){ 

var IP = "1852";
var DATE = "201410";

var select_all_sales_orders_query = "SELECT * FROM 
\"_SYS_BIC\".\"PATH_TO_CALCVIEW/CALCVIEW\"('PLACEHOLDER' =  
('$$IP$$', '"+IP+"'),('$$DATE$$', '"+DATE+"'))";


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();
10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Florian Pfeffer
Jun 17, 2017 at 01:38 PM
1

For each parameter you need the 'PLACEHOLDER' syntax. For your case:

"SELECT * FROM 
\"_SYS_BIC\".\"PATH_TO_CALCVIEW/CALCVIEW\"('PLACEHOLDER' =  
('$$IP$$', '"+IP+"'), 'PLACEHOLDER' = ('$$DATE$$', '"+DATE+"'))"

Regards,
Florian

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

Thanks for you reply Florian. I tried your solution and I keep getting the same error ("error while executing query"). I believe my code is right. I found and example in the forum with similar code but I can't figure out what's wrong with my query.

0