0
votes

im new to sapui5. i have a combobox , the user select a department, and i retrieve from the combobox the selected item name of the department. with that name im trying to do something like : select headOfUnit from FODepartment where department=(user selected name); the head of unit result ,will give me a user ID, wich i want to use to filter (varid), to get his name ,his name is in another Entity table called PerPersonal .... new sap.ui.model.Filter( "personIdExternal", "EQ", varid ) ]);

Im trying to access a specific value in the odata model using the controller section; and use it later on in a filter . (variable varid = specific value in the odata model )

     this.getView().byId("responsablenombre").getBinding("items").filter([
            new sap.ui.model.Filter(
            "personIdExternal", 
            "EQ", 
            varid  )
       ]);

i have tried : var oDataModel = this.getOwnerComponent().getModel();

           oDataModel.attachRequestCompleted(function(oEvent){
            var model = oEvent.getProperty("Text");
            var myNeededValue = model.getProperty("/FODepartment");



        });

and

             var  oDataModel =  this.getOwnerComponent().getModel();

           oDataModel.attachRequestCompleted(function() {

            var prop = oDataModel.getProperty("/FODepartment");

        });

and tried the other way /entity/(key)/atribute with no success.

when i access the variable its undefined.

when i access the oDataModel,odata i have these values

oData:

FODepartment(externalCode='31352',startDate=datetime'2018-05-14T00:00:00'): {__metadata: {…}, startDate: Mon May 14 2018 02:00:00 GMT+0200 (hora de verano de Europa central), externalCode: "31352", cust_building: null, cust_tipoSucursal: "3", …} FODepartment(externalCode='31869',startDate=datetime'1900-01-01T00:00:00'): {__metadata: {…}, startDate: Sun Dec 31 1899 23:45:16 GMT-0014 (hora estándar de Europa central), externalCode: "31869", cust_building: null, cust_tipoSucursal: "1", …}

...

PerPersonal(personIdExternal='1',startDate=datetime'1900-01-01T00:00:00'): {__metadata: {…}, startDate: Sun Dec 31 1899 23:45:16 GMT-0014 (hora estándar de Europa central), personIdExternal: "1", lastName: "MARES", nativePreferredLang: "726", …}

.

like i said i would like to know if it is posible to get a specific value ,save it in a variable and apply it later on in a filter in the controller.js

thanks in advance!

1
It is not clear from your question exactly which value you would like for varid. .getProperty("/FODepartment") will not work, as the model will not contain such a property; `.getProperty("/FODepartment(externalCode='31352',startDate=datetime'2018-05-14T00:00:00')") could work, but will return an object, and keep in mind that the data may not yet be available in the model, depending on which request has been completed... If you provide detail of which value you are interested in, I may be able to suggest how to get that value.rikusv
sorry for not being clear, the situation is the next ; i have a combobox , the user select a department, and i retrieve from the combobox the selected item name of the department. with that name im trying to do something like : select headOfUnit from FODepartment where department=(user selected name); the head of unit result ,will give me a user ID, wich i want to use to filter (varid), to get his name ,his name is in another Entity table called PerPersonal .... new sap.ui.model.Filter( "personIdExternal", "EQ", varid ) ]);jota
A good way to accomplish your objective, would be to bind the ComboBox items aggregation to "FODepartment", use the change event to get the selected item, and then get the user ID via that item, e.g. oItem.getBindingContext().getProperty("headOfUnit").rikusv
Yes, oItem.getBindingContext().getProperty("headOfUnit") did the trick! thank you so much!!..how can i validate your aswer .jota
I've added the answer. I would recommend that you update your original question with the information about the ComboBox selection.rikusv

1 Answers

0
votes

A good way to accomplish your objective, would be to bind the ComboBox items aggregation to "FODepartment", use the change event to get the selected item, and then get the user ID via that item, e.g. oItem.getBindingContext().getProperty("headOfUnit").