cancel
Showing results for 
Search instead for 
Did you mean: 

SAP UI5 odata v2 model refresh metadata

soumya_nandi
Participant

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

junwu
Active Contributor
0 Kudos

why you have to do that? your meta data change at runtime?

Accepted Solutions (0)

Answers (2)

Answers (2)

soumya_nandi
Participant
0 Kudos

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

junwu
Active Contributor
0 Kudos

how about creating entity for each of those table?

soumya_nandi
Participant
0 Kudos

Hi Jun,

I can create multiple entity types for each tables but that would be a big development as number of tables those are going to be maintained under this app is big like close to 70 - 80 tables. Hence generated this single service. If we cannot consume this then we anyway have to do in that way. But wanted to check if we can refresh the metadata any way so that a lot of development can be saved.


Regards,

Soumya

junwu
Active Contributor

I don't think reloading metadata will help. metadata has cache at server, your mpcext won't always get called.

if you know how sap odata is implemented, you can write code to generate that 100+ entity for your tables

if you don't have deep knowledge of sap odata, you can just use segw to create entity for each table. it takes some time, but one time only.

soumya_nandi
Participant
0 Kudos

Hi Jun,

Currently the mpc of my odata service gets called everytine with sone modification in the odata service. Its very much possible to call mpc all time rather than pulling it from server cache.

On the second part, I didn’t got the question. Is not creating entity for each table in segw is the only way for the odata creation? If there is some other way to generate odata in shorter time please guide me.

Regards,

Soumya

junwu
Active Contributor
0 Kudos

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.

kulkasoh
Explorer
0 Kudos

Hi Soumya,

Did you find a solution for this? I have a similar requirement to reload metadata of one Odata service used within a sapui5 app.

Thank You.

WouterLemaire
Active Contributor
0 Kudos

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

soumya_nandi
Participant
0 Kudos

Hi Wouter,

Thanks for your quick reply.

I have tried calling method refreshMetadata of the odata model but that is not refreshing the metadata might be because that is deprecated. Will the other method you mentioned is for refreshing the metadata of the model from backend server or to get the metadata from locally stored cache of the model in the app?

Regards,

Soumya

WouterLemaire
Active Contributor
0 Kudos

It will only help to read the already loaded metadata. I don’t get why you want to reload the metadata, it normally doesn’t change as long as the service doesn’t change..

soumya_nandi
Participant
0 Kudos

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