cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

DataModel Binding Anomaly

Former Member
0 Kudos
100

Hi, I have a dropdownbox:


new sap.ui.commons.DropdownBox("employeeContractType-dropdownBox", {

  visible: "{oUIProperties>/contract/visible/contractType}",

  enabled: "{oUIProperties>/contract/enabled/contractType}",

  required: "{oUIProperties>/contract/required/contractType}",

  displaySecondaryValues: true,

  selectedKey: "{ContractElementsData>/Contrtype}",

  value: "{ContractElementsData>/ContrtypeName}",

  searchHelpEnabled: true,

  searchHelp: function(oEvent) {

  sap.ui.getCore().byId("employeeContractType-dropdownBox-searchHelp").open();

  },

  layoutData: new sap.ui.layout.GridData({

  span: "L4 M4 S6",

  linebreak: false

  }),

  change: function() {

  }

});

After I create the dropdownbox I call oData webservice and set the model to my form


var oContractElementsModel = new sap.ui.model.json.JSONModel();

  oContractChangeModel.read("/ContractDetailsHRSet('" + employeeCode + "')", {

  async: false,

  success: function(oData) {

  oContractElementsModel.setData(oData);

  myForm.setModel(oContractElementsModel, "ContractElementsData");

  },

  error: function(oError) {

  console.log("Error reading ContractDetailsHRSet: ");

  console.log(oError);

  }

});

Now after i set the model i want to read the VALUE of my Dropdownbox by reading the datamodel property ContrtypeName. But for some reason it returns undefined although when I console the whole model using myForm.getModel("ContractElementsData") right before I read the property then I see that the property does have a value.

Can anyone help me out I am kind of loosing my mind because yesterday I did exactly the same thing on a different WS EntitySet and form elements and it worked fined, but now for some reason it is not working...


Can asdkjadlasdoljasContrtypeName

Accepted Solutions (0)

Answers (1)

Answers (1)

karthikarjun
Active Contributor
0 Kudos

JSON Model - It is Client Side Model

ODATA Model - Server Side Model

Try ODATA Model instead of JSON Model.

JsDoc Report - SAP UI development Toolkit for HTML5 - API Reference - sap.ui.model.odata.ODataModel

For Ex:

Simple OData Binding with SAPUI5 | SCN

Regards,

KA

Former Member
0 Kudos

I am working on the client side, I got the server side response as a client side model and set it to the form. And if I use the approach described in the Simple OData Binding with SAPUI5 | SCN answer then I can't read the model efficiently afterwards.

The data that comes from the server is read and set with no problem. It was what happenes moment after that. Plz read my question again.

karthikarjun
Active Contributor
0 Kudos

Will this help? JS Bin - Collaborative JavaScript Debugging

if Not, please share  myForm.getModel("ContractElementsData")  model data.

Regards,

KA

Former Member
0 Kudos
  1. This is the oData part of the console.log(myForm.getModel("ContractElementsData"));
  2. oData: Object
    1. Contrdate: null
    2. Contrnr: ""
    3. Contrtype: "Z3"
    4. ContrtypeName: "ametnik tähtajatu"
    5. Contrvalidto: Fri Dec 31 9999 02:00:00 GMT+0200 (FLE Standard Time)
    6. EmployeeNumber: "10017244"
    7. Residagr: null
    8. Trialper: "0"
    9. Trialperunit: ""
    10. Tsinfonr: "00"

If i to call myForm.getModel("ContractElementsData").getProperty("/ContrtypeName") then I get undefined.

former_member182372
Active Contributor
0 Kudos

what does



console.log(myForm.getModel("ContractElementsData").getData());



print?

Former Member
0 Kudos

Are You sure (myForm.getModel("ContractElementsData") is returning this?

Because getModel should return the Model Object with properties like aBindings,mContexts,oData etc..

As Maksim suggested print  myForm.getModel("ContractElementsData").getData()

Former Member
0 Kudos
  1. Object {__metadata: Object, EmployeeNumber: "10017244", Contrdate: null, Contrnr: "", Contrtype: "Z3"…}
    1. Contrdate: null
    2. Contrnr: ""
    3. Contrtype: "Z3"
    4. ContrtypeName: "ametnik tähtajatu"
    5. Contrvalidto: Fri Dec 31 9999 02:00:00 GMT+0200 (FLE Standard Time)
    6. EmployeeNumber: "10017244"
    7. Residagr: null
    8. Trialper: "0"
    9. Trialperunit: ""
    10. Tsinfonr: "00"
    11. __metadata: Object
    12. __proto__: Object

Yeah I skipped the Model Object properties and just posted the oData part of the Model Object. Perhaps there is a timing problem between when the ContrtypeName is set and when I'm trying to access it? Which still doesn't explain why the same approach works in a different place...

former_member182372
Active Contributor
0 Kudos

where is that code

myForm.getModel("ContractElementsData").getProperty("/ContrtypeName") ?


after


myForm.setModel(oContractElementsModel, "ContractElementsData");  ?



set a breakpoint a coonfigrm sequence of execution. as you said it might be timing issue