cancel
Showing results for 
Search instead for 
Did you mean: 

HANA XS

Former Member
0 Kudos

Hello all, I am new to HANA.

I am currently using hana trial version.

I have created XS application, and it was execeuted successfully, by creating hello.xsjs, xsaccess, xsapp files.

I have created a table called TEST in my inbuilt schema, and also created xsjs file in the following way,

============================================

function getDataFromTable(){

  var id = $.request.parameters.get("id"); 

  if (id === null) { 

     $.response.setContentType("text/plain"); 

     $.response.addBody("id is null!"); 

  } 

  var val1 = $.request.parameters.get("val1"); 

  if (val1 === null) { 

     $.response.setContentType("text/plain"); 

     $.response.addBody("val1 is null!"); 

  } 

  var output = {}; 

  output.data = []; 

  var conn = $.db.getConnection();

  conn.prepareStatement("SET SCHEMA \"xxxxxxxxx\"").execute(); 

  var st = conn.prepareStatement("INSERT INTO \"xxxxxxxtrial.p1234567.hello","TEST\"  values(1,K)");

  st.setString(1,id); 

  st.setString(2,val1); 

  st.executeQuery();

  st.execute(); 

  conn.commit(); 

  var record = []; 

  record.push(id); 

  record.push(val1); 

  output.data.push(record); 

  conn.close(); 

  $.response.setContentType("text/json"); 

  $.response.addBody(JSON.stringify(output)); }

along with this , also created xsaccess, xsprivileges, xsapp,  TEST.hdbtable,model_access.hbd role files .

==========================================================================================================

model_access.hbdrole ---------- (role xxxxxxxxxtrial.p1234567.hello::model_access {

     application privilege: xxxxxxxtrial.p1234567.hello::Basic;

}

But when I am trying to run the xsjs file, I am unable to see the table and inserted values , it is showing me blank page.

Could you please help me.

Accepted Solutions (1)

Accepted Solutions (1)

pfefferf
Active Contributor
0 Kudos

Hello Vinni,

there are several issues in your coding:

  • $.response.setContentType("text/plain"): setContentType is no method of the response object, instead set the property -> $.response.contentType="text/plain"
  • $.response.addBody("id is null!"): addBody is no method of the response object, instead use method setBody -> $.response.setBody("id is null!")
  • conn.prepareStatement("INSERT INTO \"xxxxxxxtrial.p1234567.hello","TEST\"  values(1,K)"):
    • not clear here what your table should be here. In case your table name is "TEST" in package "xxxxxxxtrial.p1234567.hello" than use table name "xxxxxxxtrial.p1234567.hello::TEST"
    • also the values "(1, K)" are somehow fixed here, because you are setting the values with the setString method of the statement you have to use placeholder in your statement
    • Statement can look like following: conn.prepareStatement("INSERT INTO \"xxxxxxxtrial.p1234567.hello::TEST\"  values(?,?)");
  • Furthermore: Do you have defined a role which gives you the INSERT privilege on your table?

Best Regards,

Florian

Former Member
0 Kudos

Hi Florian,

Thanks for your response.

I have changed the code as you told, and also created model_access.hdbrole file as below.

role sxxxxxxtrial.p1234567.hello::model_access {

     sql object sxxxxxxrial.p1234567.hello::TEST: INSERT, SELECT;

   

     }

[ p1234567.hello - package, TEST - table name]

Given below statement also

call "HCP"."HCP_GRANT_ROLE_TO_USER"('sxxxxxtrial.p1234567.hello::model_access', 'sxxxxx')

==========================================

Below is the error for that :

Could not execute 'call "HCP"."HCP_GRANT_ROLE_TO_USER"('sxxxxxxtrial.p1234567.hello::model_access', 'sxxxxx')' in 18.132 seconds .

[129]: transaction rolled back by an internal error:  [129] "HCP"."HCP_GRANT_ROLE_TO_USER": line 14 col 11 (at pos 849): [129] (range 3): transaction rolled back by an internal error: transaction rolled back by an internal error:  [129] "HCP"."SYNCHRONIZE_HCP_ROLES": line 22 col 12 (at pos 1518): [129] (range 3): transaction rolled back by an internal error: transaction rolled back by an internal error:  [129] "HCP"."SYNCHRONIZE_HCP_ROLE": line 43 col 4 (at pos 2768): [129] (range 3): transaction rolled back by an internal error: user-defined error:  [10001] "HCP"."DEPENDENCY_VALIDATOR": line 81 col 9 (at pos 4881): [10001] (range 3) user-defined error exception: Checking object: schema: DEV_73G1DE1342LB7K9C54J138R1E, object: sxxxxxxxtrial.p1234567.CRM::customer. User DEV_73G1DE1342LB7K9C54J138R1E is not authorized for:  Object: sxxxxxtrial.p1234567.CRM::customer Schema: DEV_73G1DE1342LB7K9C54J138R1E Type: TABLE

I have activated all files successfully, but when  I run XSjs file  (https://s8hanaxs.hanatrial.ondemand.com/sxxxxxxxtrial/p1234567/hello/hello.xsjs?id=1&&val1=6)  It is showing a blank page

pfefferf
Active Contributor
0 Kudos

You should move your table to your specific NEO schema. Your specific NEO schema can be found by selecting it from view "HCP"."HCP_DEV_METADATA".

Best Regards,

Florian

Former Member
0 Kudos

Hi Florian,

Thanks for the quick response

I have moved my Table TEST into my schema as you told.

But still facing same error when I execute call "HCP"."HCP_GRANT_ROLE_TO_USER"


('s00xxxxxxxtrial.p1234567.hello::model_access', 's00xxxxx').

In xsjs file also I have changed  schema name in " set schema statement ".

Given , SELECT * FROM "HCP"."HCP_DEV_METADATA

I got as below

=============================

SCHEMA_NAME;PACKAGE_NAME;ROLE_NAME

NEO_xxxxxxxxxxxxxxxxxxxx;

Package name : s00xxxxxrial.p1234567;

Role name : NEO_s00xxxxxxtrial.p1234567_DEV

Blank page while I am running xsjs file

hello - xsjs project folder name.

package - S00xxxtrial

subpackage - p1234567

Subpackages - CRM, hello

currently, the  files I have created are stored in hello sub package.

pfefferf
Active Contributor
0 Kudos

It seems that you have still object in the DEV schema, cause in the error message a table "...::customer" is mentioned. You have to move all objects to the NEO schema.

Former Member
0 Kudos

Hi florian,

Your answer is so helpful florian.

Have moved all the objects and activated all the objects, I am also able to run the below statement.

call "HCP"."HCP_GRANT_SELECT_ON_ACTIVATED_OBJECT"('s0014485595trial.p1234567.hello', 'TESTS')

But tried to open this url,

https://s8hanaxs.hanatrial.ondemand.com/sxxxxxxxtrial/p1234567/hello/hello.xsjs?id=1&&val1=6)  It is showing a blank page again.

Could you tell me what all steps do I need to take apart from this and also how to do

a HTTP GET to the URL pointing to my  .xsjs file, passing the URL parameters.

pfefferf
Active Contributor
0 Kudos

Do you have any entries in your table matching your input parameters?

What says the console of your browser?

Did you debug the XSJS already?

Former Member
0 Kudos

Hi Florian,

Yea I have entries ( id=1 && val=6). Once I activate the files and giving call statement in SQL. I am running xs application in web based development workbench. But when I open the application Blank page is diplayed.

====================================

Hello.xsjs

function getDataFromTable() {

var id = $.request.parameters.get("id");

  if (id === null) { 

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

$.response.setBody("id is null!") ;

  } 

  var val1 = $.request.parameters.get("val1"); 

  if (val1 === null) { 

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

  $.response.setBody("val1 is null!");

  }

  var output = {}; 

  output.data = []; 

  var conn = $.db.getConnection();

conn.prepareStatement("SET SCHEMA \"NEO_xxxxxxxNGHC4\"").execute(); 

var st = conn.prepareStatement("INSERT INTO \"sxxxxxxrial.p1234567.hello::TESTS\"  values(?,?)");

st.setString(1,id); 

st.setString(2,val1);

st.executeQuery();

st.execute(); 

  conn.commit(); 

  var record = []; 

  record.push(id); 

  record.push(val1); 

  output.data.push(record); 

  conn.close(); 

}

=============================================

.xsaccess :

{

"exposed" : true,

"default_file": "hello.xsjs"

}

=================================================

.xapp

          "auth_required": true 

}

=================================

model_access.hdbrole:

role sxxxxxxtrial.p1234567.hello::model_access {

     sql object sxxxxxxtrial.p1234567.hello::TESTS: INSERT, SELECT;

    

     }

Could you please tell me any other changes / steps I miss.

Are there any configurations do I need to follow?

I am using http://scn.sap.com/community/developer-center/cloud-platform/blog/2014/06/19/debug-your-sap-hana-xs-... for debugging xs.

But I got struck in step 3 since It is displaying blank page.

Thanks in Advance,

Vinni

pfefferf
Active Contributor
0 Kudos

Where is the call of function "getDataFromTable" in your Hello.xsjs? Do you set in your new version any response after your insert statement? The line with "st.executeQuery()" can be removed because it is not necessary for the insert.

Maybe you can set at the end a response body like a string "ok" to check if anything is returned and your script is at least executed.

Answers (1)

Answers (1)

0 Kudos

hi vinni,

you can check host file under the folder etc