Hi experts,
I want to consume odata, and the create rule follow userCreate.xsjslib .
userlib.xsodata
service { "sap.hana.democontent.epm.data::EPM.User.Details" as "Users" create using "lly.xsjslib:userCreate.xsjslib::userCreate" ; }
userCreate.xsjslib
function userCreate(o) { $.trace.debug("entered function"); // to get max person number var l_PERS_NO ; var l_FIRSTNAME = o.FIRSTNAME; var l_LASTNAME = o.LASTNAME; var l_MAIL = o.E_MAIL; var conn = $.db.getConnection(); if( l_MAIL == 'mail' ) { throw "create error" ; } // to get the newest userid var pStmt = conn.prepareStatement('select "sap.hana.democontent.epm.data::userSeqId".NEXTVAL from dummy'); var rs = pStmt.executeQuery() ; while (rs.next()) { l_PERS_NO = rs.getString(1) ; } rs.close(); pStmt = conn.prepareStatement('insert into "sap.hana.democontent.epm.data::EPM.User.Details" values(?, ?, ?, ?)'); pStmt.setString(1, l_PERS_NO); pStmt.setString(2, l_FIRSTNAME); pStmt.setString(3, l_LASTNAME); pStmt.setString(4, l_MAIL); pStmt.executeUpdate(); conn.commit(); pStmt.close(); conn.close(); }
UI5 view code: createContent
this.oModel = new sap.ui.model.odata.ODataModel("http://xx/odata/userlib.xsodata", false); ...... var oVal1 = new sap.ui.commons.TextField("fName",{tooltip: "First Name", width: "200px", editable:true}); var oVal2 = new sap.ui.commons.TextField("lName",{tooltip: "Last Name", width: "200px", editable:true}); var oVal3 = new sap.ui.commons.TextField("email",{tooltip: "Email", width: "200px", editable:true}); var oExcButton = new sap.ui.commons.Button({ text : "Create Record", press : oController.callUserService }); .... oTable.setModel(this.oModel); oTable.bindRows("/Users"); oTable.setTitle("Users" ); oTable.setEditable(true); oLayout.createRow(oTable); return oLayout;
UI5 controller code:
callUserService : function() { var oModel = sap.ui.getCore().byId("userTbl").getModel(); var oEntry = {}; oEntry.PERS_NO = '0000000'; oEntry.FIRSTNAME = sap.ui.getCore().byId("fName").getValue(); oEntry.LASTNAME = sap.ui.getCore().byId("lName").getValue(); oEntry.E_MAIL = sap.ui.getCore().byId("email").getValue(); oModel.setHeaders({"content-type" : "application/json;charset=utf-8"}); oModel.create('/Users', oEntry, null, function() { alert("Create successful"); }, function() { alert("Create failed"); }); },
Q1: I debug this session, and found no parameter pass to userCreate.xsjslib,
how can i pass value to parameter 'o'?
Q2: if I use the syntax create events (before "lly.xsjslib:userCreate.xsjslib::userCreate"),
I found can't use function like "$.", why? and how can i fix it ?
Q3: how to understand create events (before xx), or is there one guider to explain it ?
Thank you & best regards
Elan