Skip to Content
avatar image
Former Member

SAP HANA XS - Unable to debug .xsjslib from postman.

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,

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Mar 22, 2017 at 11:30 AM

    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.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Mar 29, 2017 at 06:22 AM

    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."}}}

    batch.jpg

    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,

    Add comment
    10|10000 characters needed characters exceeded