Skip to Content
0

How to announce a parameter in url for XSJS

Mar 29, 2017 at 12:13 PM

15

avatar image

Hi guys, I have this functional code :

var conn = $.db.getConnection("howdoyoufeel::anouser");

var output = {results: [] };

var vote1 = "SELECT COUNT(C_VOTE) FROM HOWDOYOUFEEL.T_IOT_2E608BE9A3C0ECBDCCF6 WHERE C_VOTE=1";
var vote2 = "SELECT COUNT(C_VOTE) FROM HOWDOYOUFEEL.T_IOT_2E608BE9A3C0ECBDCCF6 WHERE C_VOTE=0";

var pstmt = conn.prepareStatement(vote1);
var rs = pstmt.executeQuery();

while(rs.next()){


	output.results.push({
  
	  "C_VOTE" : rs.getString(1)
  });


}

var pstmt = conn.prepareStatement(vote2);
var rs = pstmt.executeQuery();

while(rs.next()){


	output.results.push({
  
	  "C_VOTE" : rs.getString(1)
  });


}
rs.close();
pstmt.close();
conn.close();

var body = JSON.stringify(output);
$.response.contentType = 'application/json';
$.response.setBody(body);
$.response.status = $.net.http.OK;

And I wanted to add in the request :

SELECT COUNT(C_VOTE), C_ID_PROJECT FROM HOWDOYOUFEEL.T_IOT_2E608BE9A3C0ECBDCCF6 WHERE C_VOTE=1 AND C_ID_PROJECT = ?;

I wanted to choose the parameter C_ID_PROJECT in the url of the xsjs service, but i did not succeed. Could you help me please ?

Thank you in advance and sorry for my approximate english.

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

1 Answer

Best Answer
Milan Camus Mar 29, 2017 at 01:44 PM
0

Fixed it, it works !

var conn = $.db.getConnection("howdoyoufeel::anouser");


var output = {results: [] };


var votePos = "SELECT COUNT(C_VOTE) FROM HOWDOYOUFEEL.T_IOT_2E608BE9A3C0ECBDCCF6 WHERE C_VOTE=0";
var voteNeg = "SELECT COUNT(C_VOTE) FROM HOWDOYOUFEEL.T_IOT_2E608BE9A3C0ECBDCCF6 WHERE C_VOTE=1";


var project = $.request.parameters.get('project');
if(project) {
	votePos = votePos + " AND C_ID_PROJECT=" + project;
	voteNeg = voteNeg + " AND C_ID_PROJECT=" + project;
}


var pstmt = conn.prepareStatement(votePos);
var rs = pstmt.executeQuery();


while(rs.next()){


	output.results.push(rs.getString(1));


}


var pstmt = conn.prepareStatement(voteNeg);
var rs = pstmt.executeQuery();


while(rs.next()){


	output.results.push(rs.getString(1));


}


rs.close();
pstmt.close();
conn.close();


var body = JSON.stringify(output);
$.response.contentType = 'application/json';
$.response.setBody(body);
$.response.status = $.net.http.OK;
Share
10 |10000 characters needed characters left characters exceeded