cancel
Showing results for 
Search instead for 
Did you mean: 

XSJS calls

Former Member
0 Kudos

Hello, I have a problem. I have .xsjs and index.html. And I need to get values from .html sample form to .xsjs file.

My function .html file:


function openCreateDialog(){

        

                var oCreateDialog = new sap.ui.commons.Dialog();

                oCreateDialog.setTitle("Sukurti įrašą");

                var oSimpleForm = new sap.ui.layout.form.SimpleForm({

                    maxContainerCols: 2,

                    content:[

                        new sap.ui.core.Title({text:"Duomenys"}),

                        new sap.ui.commons.Label({text:"ID"}),

                        new sap.ui.commons.TextField('id',{value:""}),

                        new sap.ui.commons.Label({text:"Vardas"}),

                        new sap.ui.commons.TextField('name',{value:""}),

                        new sap.ui.commons.Label({text:"Pavardė"}),

                        new sap.ui.commons.TextField('surname',{value:""}),

                        new sap.ui.commons.Label({text:"Telefono numeris"}),

                        new sap.ui.commons.TextField('mobilenumber',{value:""}),

                        new sap.ui.commons.Label({text:"E. paštas"}),

                        new sap.ui.commons.TextField('email',{value:""}),

                        new sap.ui.commons.Label({text:"Galioja nuo"}),

                        new sap.ui.commons.TextField('pdata',{value:""}),

                        new sap.ui.commons.Label({text:"Galioja iki"}),

                        new sap.ui.commons.TextField('enddata',{value:""}),

                        new sap.ui.commons.Label({text:"Kompanija"}),

                        new sap.ui.commons.TextField('company',{value:""}),

                        ]                                                                      

                });

           ///////////////////////////////////////////////////////////////////////

                oCreateDialog.addContent(oSimpleForm);

                oCreateDialog.addButton(

                    new sap.ui.commons.Button({

                        text: "Sukurti",

                        press: function() {

                    

                        var ID = $('#id').val();

                        var NAME = $('#name').val();

                        var SURNAME = $('#surname').val();

                        var MOBILENUMBER = $('#mobilenumber').val();

                        var EMAIL = $('#email').val();

                        var PDATA = $('#pdata').val();

                        var ENDDATA = $('#enddata').val();

                        var COMPANY = $('#company').val();

                      

                           // );

                        }

                    })

                );

and my .xsjs file


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

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

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

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

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

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

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

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

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

var conn  = $.db.getConnection();

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

var query = "INSERT INTO \"p1940820305trial.hanaxs.Programa.Data::LG\" values(?,?,?,?,?,?,?,?,)";

var pstmt = conn.prepareStatement(query);

pstmt.setString(1,ID);

pstmt.setString(2,NAME);

pstmt.setString(3,SURNAME);

pstmt.setString(4,MOBILENUMBER);

pstmt.setString(5,EMAIL);

pstmt.setString(6,PDATA);

pstmt.setString(7,ENDDATA);

pstmt.setString(8,COMPANY);

pstmt.execute();

conn.commit();                                                                                                                                                

pstmt.close();                                                                        

conn.close();                                                               

$.response.setBody(query);

So, how to get values for my sql statement from .html file ?

Accepted Solutions (1)

Accepted Solutions (1)

former_member191806
Active Participant
0 Kudos

Hello Justas,

Firstly I would say that you should try and group your controls in fragments or views. Also, a better way to get the values of your controls is by using sap.ui.getCore().byId("controlId").getValue(). The way you used is not 100% guaranteed to work (if for example you would embed your controls in a view, it would certainly not work).

To pass the values to the xsjs script, you need to make a GET AJAX request (or POST, but you have written your script for GET requests). This is an example of how you can do it:

$.get({
  url: "/path/to/your.file.xsjs",

  data: {ID: sap.ui.getCore().byId("id").getValue(), NAME: ...},

  success: function(oData, status) {
          //here you can handle the response
  }
});

Best Regards,

Serban

Answers (0)