Skip to Content

SAP UI5 odata v2 model refresh metadata

Hi Experts,


I got stuck to a requirement where I need to update the metadata of my odata model of sap ui5 application at runtime based on some user action.


Can anyone guide me on how I can refresh the metadata of an odata v2 model? If we cannot then is there any alternative to achieve the same result like doing a ajax call or something?

Regards,

Soumya

Add a comment
10|10000 characters needed characters exceeded

Related questions

2 Answers

  • Posted on Apr 07 at 07:33 AM

    Have you tried the function getMetaModel of the OData model? https://ui5.sap.com/#/api/sap.ui.model.odata.v2.ODataModel%23methods/getMetaModel

    There is also a function for refreshing but I would not recommend using it https://ui5.sap.com/#/api/sap.ui.model.odata.v2.ODataModel%23methods/refreshMetadata

    Add a comment
    10|10000 characters needed characters exceeded

    • Hi Wouter,

      Yes that is for static odata service for which the fields doesn’t change at runtime. But the odata service I have created have some addition/removal of fields in MPC based on user selection in the ui5 screen.
      So I am facing the issue once the user selection happens and post which user is trying to perform any of the crud operation. I am getting error like “Cannot read property data of field xxxx in entity type xxxx” which is correct because that is added later post user selection.

      Let me know if you need any further clarification.


      Regards,

      Soumya

  • Posted on Apr 07 at 11:30 PM

    Hi Jun,

    Yes my metadata changes at runtime based on user selection in the ui5 screen. Below is the requirement,

    We had webdynpro java application and few brm rules, using which one application can handle crud operation in almost 100 of tables. Now as part migration to sapui5 from old screens to new screen post hana update we are trying to replicate the same app in ui5 now. I have created an odata service which is capable of performing crud operations on all tables in sap abap system. Now while consuming that service into mu ui5 application is giving me real challenge. As for the first time when user is loading the app and choosing any table they can perform crud operation on that table but if they change the table selection then error coming as “Cannot read property of fields xxxx of entity xxxx” which is correct as the metadata is not changed based on selection. Hence I am looking for a help on the metadata update at runtime.
    Let me know if you want any further clarification.

    Regards,

    Soumya

    Add a comment
    10|10000 characters needed characters exceeded

    • for now you are changing the mpcext, that's why is getting called every time. once your mpcext stabilized, cache will come to play, your code won't be called.

      entity created in segw is just to facilitate the odata creation, it is just to create code for mpc, which is the real mother of entity, you can write similar code to create entity.

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.