cancel
Showing results for 
Search instead for 
Did you mean: 

How to update procedure results set into table in XSA XSJS file?

former_member356171
Participant
0 Kudos

Hi,

I am currently doing the development in HANA XSA Web ide, Reading the HANA procedure results and trying to update custom table with the results set in XSJS file. Could anyone please help me how to do that? Below is the code, How to parse the results into corresponding fields.

Facing errors while updating the data. Values in "results" are in JSON format.

Ex: id:1, name: Emp1, number:1111

id:2, name: Emp2, number:2222 etc.,

function create() {
var conn;
conn = $.hdb.getConnection();
var getProcedureData = conn.loadProcedure("xsajobsXSJS.db::EmpProcedure");
var results = getProcedureData();
conn.executeUpdate('INSERT INTO "xsajobsXSJS.db::tables.EmpData_2" (id, name, number) VALUES(?)',results);
conn.commit();
conn.close();

Accepted Solutions (1)

Accepted Solutions (1)

Cocquerel
Active Contributor
0 Kudos

I think your coding should looks like this

conn.executeUpdate('INSERT INTO "xsajobsXSJS.db::tables.EmpData_2" (id, name, number) VALUES(?,?,?)',results.id,results.name,results.number);
former_member356171
Participant
0 Kudos

Hi Michael,

I tried that way, but receiving error "execution failed: Cannot read property 'ID' of undefined#".

Attached are the results set values.

Cocquerel
Active Contributor
0 Kudos

You may need to first run "results = JSON.parse(results);" if results is not an object but a string.

Then, the coding should looks like this.

for (i = 0; i < results[0].length; ++i) {
conn.executeUpdate('INSERT INTO "xsajobsXSJS.db::tables.EmpData_2" (id, name, number) VALUES(?,?,?)',results[0][i].id,results[0][i].name,results[0][i].number);
}
former_member356171
Participant
0 Kudos

Thanks Michael for the inputs, it is working now.

Answers (0)