on 03-22-2017 5:14 AM
Hi ,
I am using $batch option to insert or update multiple records.
I have created the .xsodata , .xsjslib files and able to execute the postman with 202 status but records are inserting into respective tables. tried to debug the js file, it is not triggering from postman .below are the details which i used please check and help on this.
POSTMAN:
URL:https://XXl.hanatrial.ondemand.com/workshop/exercises/g001/service.xsodata/$batch
Parameters:
Accept:application/json
Content-Type:multipart/mixed; boundary=batch
x-csrf-token:901F634DD72A2E49A4A72CA89DADB8CF
Raw:
--batch Content - Type: multipart / mixed; boundary = changeset Content - Transfer - Encoding: binary --changeset Content - Type: application / http Content - Transfer - Encoding: binary Content - ID: 1 POST POHeader HTTP / 1.1 Content - Type: application / json Content - Length: 82 { "PURCHASEORDERID": "0300000003", "HISTORY.CREATEDBY": "", "HISTORY.CREATEDAT": "/Date(1488931200000)/", "HISTORY.CHANGEDBY": "", "HISTORY.CHANGEDAT": null, "NOTEID": "", "PARTNER": "0100000000", "CURRENCY": "ERU", "GROSSAMOUNT": "359072.23", "NETAMOUNT": "32345.11", "TAXAMOUNT": "4467.25", "LIFECYCLESTATUS": "1", "APPROVALSTATUS": "G", "CONFIRMSTATUS": "E", "ORDERINGSTATUS": "C", "INVOICINGSTATUS": "A" } --changeset Content - Type: application / http Content - Transfer - Encoding: binary Content - ID: 2 POST POItem HTTP / 1.1 Content - Type: application / json Content - Length: 45 { "PURCHASEORDERID": "0300000003", "PURCHASEORDERITEM": "000010", "PRODUCT": "HT-610", "NOTEID": "", "CURRENCY": "ERU", "GROSSAMOUNT": "329508.01", "NETAMOUNT": "779899", "TAXAMOUNT": "6732.04", "QUANTITY": "287.15", "QUANTITYUNIT": "EA", "DELIVERYDATE": "/Date(1496361600000)/" } --changeset Content - Type: application / http Content - Transfer - Encoding: binary PUT $1 / $links / POItem HTTP / 1.1 Content - Type: application / json Content - Length: 12 {"uri": "$2"} --changeset-- --batch--
.xsodata:
service namespace "workshop.exercises.g001.service" { "workshop.exercises.g001::PurchaseOrder.Header" as "POHeader" navigates ("Items" as "POItem") create events(before "workshop.exercises.g001:POHeaderPOItem.xsjslib::poheader_create_before_exiit"); "workshop.exercises.g001::PurchaseOrder.Item" as "POItem" create events(before "workshop.exercises.g001:POHeaderPOItem.xsjslib::poitem_create_before_exiit"); association "Items" principal "POHeader"("PURCHASEORDERID") multiplicity "1" dependent "POItem"("PURCHASEORDERID") multiplicity "*" over "workshop.exercises.g001::PurchaseOrder.Item" principal ("PURCHASEORDERID") dependent ("PURCHASEORDERID") update using "workshop.exercises.g001:POHeaderPOItem.xsjslib::association_create_exit"; }
.xsjslib:
$.import("workshop.exercises.g001.service", "session"); var SESSIONINFO = $.workshop.exercises.g001.service.session; /** @param {connection} Connection - The SQL connection used in the OData request @param {beforeTableName} String - The name of a temporary table with the single entry before the operation (UPDATE and DELETE events only) @param {afterTableName} String -The name of a temporary table with the single entry after the operation (CREATE and UPDATE events only) */ function poheader_create_before_exiit(param){ let after = param.afterTableName; var pStmt; try{ pStmt = param.connection.prepareStatment('select "workshop.exercises.g001::PurchaseOrderId".NEXTVAL from dummy' ); var rs = pStmt.executeQuery(); var PohId = ''; while (rs.next()) { PohId = rs.getString(1); } pStmt.close(); pStmt = param.connection.prepareStatement('update "' + after + '" set PURCHASEORDERID = ? ,' + '"HISTORY.CREATEDBY"= ?,' + '"HISTORY.CREATEDAT"= ?,' + '"HISTORY.CHANGEDBY"= ?,' + '"HISTORY.CHANGEDAT"= ?,' + '"NOTEID"=? ,' + '"PARTNER"= ? ,' + '"CURRENCY"=?,' + '"GROSSAMOUNT"=?,' + '"NETAMOUNT"=? ,' + '"TAXAMOUNT"=? ,' + '"LIFECYCLESTATUS"=? ,' + '"APPROVALSTATUS"=? ,' + '"CONFIRMSTATUS"=? ,' + '"ORDERINGSTATUS"=? ,' + '"INVOICINGSTATUS"=? ,'); pStmt.setString(1, PohId); pStmt.setString(2, ' '); pStmt.setString(3, ' '); pStmt.setString(4, ' '); pStmt.setString(5, ' '); pStmt.setString(6, '01'); pStmt.setString(7, '0200000000'); pStmt.setString(8, 'EUR'); pStmt.setString(9, '234.45'); pStmt.setString(10, '8764.12'); pStmt.setString(11, '234.56'); pStmt.setString(12, 'A'); pStmt.setString(13, 'B'); pStmt.setString(14, 'C'); pStmt.setString(15, 'D'); pStmt.setString(16, 'E'); pStmt.execute(); pStmt.close(); } catch (e) { } } function poitem_create_before_exiit(param) { let after = param.afterTableName; var pStmt; try { pStmt = param.connection.prepareStatement('select "workshop.exercises.g001::PurchaseOrderId".NEXTVAL from dummy'); var rs = pStmt.executeQuery(); var PoiId = ''; while (rs.next()) { PoiId = rs.getString(1); } pStmt.close(); pStmt = param.connection.prepareStatement('update "' + after + '" set PURCHASEORDERID = ? ,' + '"PURCHASEORDERITEM"= ?,' + '"PRODUCT"= ?,' + '"NOTEID"= ?,' + '"CURRENCY"= ?,' + '"GROSSAMOUNT"=? ,' + '"NETAMOUNT"= ? ,' + '"TAXAMOUNT"=?,' + '"QUANTITY"=?,' + '"QUANTITYUNIT"=? ,' + '"DELIVERYDATE"=? ,'); pStmt.setString(1, PoiId); pStmt.setString(2, ' '); pStmt.setString(3, ' '); pStmt.setString(4, ' '); pStmt.setString(5, ' '); pStmt.setString(6, ' '); pStmt.setString(7, ' '); pStmt.setString(8, ' '); pStmt.setString(9, ' '); pStmt.setString(10, ' '); pStmt.setString(11, ' '); pStmt.execute(); pStmt.close(); } catch (e) { } } function association_create_exit(param){ let princ = param.principalTableName; let dep = param.dependentTableName; var pStmt = param.connection.prepareStatement('select * from "' + princ + '"'); var Principal = SESSIONINFO.recordSetToJSON(pStmt.executeQuery(), 'Details'); pStmt.close(); var pStmt1 = param.connection.prepareStatement('select * from "' + dep + '"'); var Dependent = SESSIONINFO.recordSetToJSON(pStmt.executeQuery(), 'Details'); pStmt1.close(); $.trace.debug(JSON.stringify(Principal)); $.trace.debug(JSON.stringify(Dependent)); var pStmt2 = param.connection.prepareStatement('update "schema"."workshop.exercises.g001::PurchaseOrder.Header" ' + ' SET "PURCHASEORDERID" = ? WHERE "PURCHASEORDERID" = ? '); pStmt2.setString(1, Dependent.Details[0].ADDRESSID); pStmt2.setString(2, Principal.Details[0].PARTNERID); pStmt2.execute(); pStmt2.close(); }
Thanks,
Hi Thomas,
I am trying to run the $batch service with the below request header and body from postman and getting error as "Invalid multipart entry.".can you please help me on this issue.attached the screenshot for the reference.
If i change the values in request body as {"PURCHASEORDERID" : 14 } getting error as { "error": { "code": "", "message": { "lang": "en-US", "value": "Error processing request stream. JSON text specified is not valid."}}}
Service:
service {"workshop.exercises.g001::PurchaseOrder.Header1" as "POHeader1" create events(before "workshop.exercises.g001:POHeaderPOItem.xsjslib::poheader_create_before_exiit");
}
.xsjslib:
function poheader_create_before_exiit(param){ let after = param.afterTableName; var pStmt = null;
try{ pStmt = param.connection.prepareStatment('select "workshop.exercises.g001::PurchaseOrderId".NEXTVAL from dummy' );
var rs = pStmt.executeQuery();
var PohId = '';
while (rs.next())
{ PohId = rs.getString(1); }
pStmt.close(); pStmt = param.connection.prepareStatement("update\"" + after + "\" set PURCHASEORDERID = ?");
pStmt.setString(1, PohId);
pStmt.execute();
pStmt.close();
}
catch (e)
{ pStmt.close();
}
}
Thanks,
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Debugging XSJS requires a special debugging cookie to be placed into the request. When you debug from the HANA Studio or Web-Workbench this cookie is set automatically for you. An external tool, like Postman, won't know about this cookie.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Thomas,
Thanks for your response.
But other scenarios we are able to debug form external tool (postman) without $batch (Single insert with .hdbprocedure).
I need your suggestion on the below requirement.
We have three tables with common key ‘PURCHASEORDERID’, created association between these three and we will get the data (Header, Item and ItmMat) from UI at one shot (submit the data in one payload).
Now that data need to be process and insert into respective tables (we will have multiple records in Item and ItmMat). Can you please suggest how to proceed? and share any example if you have.
Tables:
"workshop.exercises.g001::PurchaseOrder.Header"
"workshop.exercises.g001::PurchaseOrder.Item"
"workshop.exercises.g001::PurchaseOrder.ItmMat"
Example:
Header-
PURCHASEORDERID HISTORY.CREATEDBY CURRENCY GROSSAMOUNT NETAMOUNT TAXAMOUNT 300000001 USHI EUR 345 231 23 300000002 USHI EUR 678 525 45Item-
PURCHASEORDERID PURCHASEORDERITEM QUANTITY PRODUCT CURRENCY GROSSAMOUNT NETAMOUNT TAXAMOUNT 300000001 10 2 EUR 567 231 23 300000002 20 5 EUR 987 525 45ItmMat-
PURCHASEORDERID ITEM MATERIAL QUANTITY PRODUCT CURRENCY GROSSAMOUNT NETAMOUNT TAXAMOUNT 300000001 10 9076521 4 EUR 567 231 23 300000002 20 9076523 3 EUR 987 525 45Thanks,
Hi Thomas,
For Multi insert to
different tables, we are following 2 approach
1 - $BATCH - sending all the payload in batch request
2 - XSJS - We have created xsjs file and implemented the logic to get the
multiple array and insert the record in multiple table. From POSTMAN we are
calling the service of .xsjs and sending the request as deep insert format.
From above 2 approaches which we need to prefer on performance basis.?
Thanks,
Hi Thomas & SHADOW
I have created the Procedure--> Insert the multiple record at a time (I am written script format)
Input & output is Table type
PROCEDURE "SCHEMA"."PACKAGE::SP_CREATE" (IN I_TAB "SCHEMA"."TT_EMP", OUT O_MSG "SCHEMA"."TT_MSGTYPE")
----I have written my code
End
I have written xsodata
service namespace "PACKAGE"{
"SCHEMA"."VENDOR" as "VENCRE"
create using "PACKAGE::SP_CREATE";
}
I have unable to insert the multiple records into database that i got 202 accept
how debug the procedure from postman
how to avoid 202 accepted request
User | Count |
---|---|
89 | |
10 | |
9 | |
9 | |
9 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.