cancel
Showing results for 
Search instead for 
Did you mean: 

JSON model loaded but no data

uwe_isenmann2
Participant
0 Kudos
925

Hello together,

What I want to do is:

- load a model with some data from a local json file

In the WebIde the data will be loaded correctly but when I deploy the application to the backend I'm not able to read the propertys.

The SAPUI5 Versions are:

- WebIDE: 1.56.10

- Backend: 1.52.09 (Should be newest stable Version)

I have a Json File (model/AppData.json):

{ "AddData":{ 	<br>	"IdKunnr": "0000000035" }
}

manifest.json:

"models":{    <br>	"AppData": { 	<br>		"type": "sap.ui.model.json.JSONModel", 	"settings": {}, 	<br>		"uri": "model/AppData.json", "preload": true }

}

In a Controller I try to Access the data:

onAddItem: function (oEvent) {  

	var v1 = this.getView().getModel("AppData").getProperty("/AppData/IdKunnr");

...


v1 is undifined (when I test in backend - in SAP Web Ide all works fine).

When I debug the coding I can see the the model "AppData" exists but has no Content in the oData Variable.

Perhaps anybody can help me.

Best regards

Accepted Solutions (0)

Answers (13)

Answers (13)

arthursilva
Active Participant

Hello Uwe

Your "model" configuration seems right. but your getModel call doesnt. The model AppData is a application component, which is not visible at controller level (local scope). So, you should use getModel at the global scope, just like below:

this.getOwnerComponent().getModel("AddData");

Models defined in manifest should be called through this.getOwnerComponent().

BR
Arthur Silva

uwe_isenmann2
Participant
0 Kudos

Nobody - Maybe anybody from SAP.

I would also be happy if anybody would say that I couldn't use this concept in an AS ABAP FLP Application.

uwe_isenmann2
Participant
0 Kudos

Hello,

Thank you for your example but it is not a complete project and I don't understand why are you try to load the model - I think the framework should do this if the file is referenced in the manifest file.

Can anybody please share a complete GitHub project:

  1. that contains a simple json model in the model folder (maybe single value with "hello world")
  2. the json model is only referenced in the manifest file
  3. and the Value will be displayed on a View (maybe xml view)
  4. that work in WebIde Development environment
  5. that could deployment on an ABAP Application Server
  6. that also works in the Fiori Launch Pad on the ABAP Application Server

For me point 6 is very important!

My sample application will work standalone on AS ABAP but not in the Fiori Launch Pad

Best Regards
Uwe

uwe_isenmann2
Participant
0 Kudos

Hello together,

Thank you for your response but I am not getting any working application (on AS ABAP in FLP).

Two questions:
1. Can anybody send me an link to a simple example project (maybe GitHub) which is showing data out of a json file and witch should also work on AS ABAP FLP? Maybe it is a wrong configuration in AS ABAP.

2. Is there any documentation about the differences between running Apps in Web IDE FLP and running Apps in AS ABAP FLP? Generally, json files which are defined in manifest.json should be loaded automatically. Why not on AS ABAP FLP?

Best regards

Uwe

arthursilva
Active Participant
0 Kudos

Hello,

Here's an example:

https://jsfiddle.net/7wdv8pL1

Btw, your manifest.json will be read at same time your Component.js is loaded. So no difference between ABAP and FLP.

BR
Arthur Silva

uwe_isenmann2
Participant
0 Kudos

I tried both:

var path = jQuery.sap.getModulePath("Z_LOP_WORKLIST/Z_LOP_WORKLIST", "/model/AppData.json");
path = jQuery.sap.getModulePath("Z_LOP_WORKLIST.Z_LOP_WORKLIST", "/model/AppData.json");

I think we searching on the wrong location.

Is there no simple github project which is loading a simple json file? (Generally: json models which are defined in manifest.json should be loaded automatically, or not?)

junwu
Active Contributor
0 Kudos

are you sure this one is not working? what error msg you get?

path = jQuery.sap.getModulePath("Z_LOP_WORKLIST.Z_LOP_WORKLIST", "/model/AppData.json");
junwu
Active Contributor
0 Kudos

then you should put z_lop_worklist.z_lop_worklist in the call, no need to change to /

uwe_isenmann2
Participant
0 Kudos

No. My ID is z_lop_worklist.z_lop_worklist. I know it's not the best ID or namespace. But it should work fine, or not?

Is there a example project at gitgub or something else (with a simple json file) which should also work fine an ABAP Stack?

junwu
Active Contributor
0 Kudos

then you should put z_lop_worklist.z_lop_worklist in the call, no need to change to /

junwu
Active Contributor
0 Kudos

why your id is z_lop_worklist/z_lop_worklist? you have / in between?

uwe_isenmann2
Participant
0 Kudos

Hello Jun, Hello Pinaki,

Thank you for your response. Yes I took value from "sap.app":{"id":....

In WebIde all works fine. But when I deploy the app to our abap backend the json file could not be loaded.

I can see that in runtime mode the component is separated into different Folders:

  • Component.js and Componenten-preload.js is in Folder ...ui5_ui5/sap/z_tcs_test2/~....
  • the other files under ui2/undefined/test/Z_TEST

I don't understand what is wrong. I made a simple Project which loads a simple json file:

https://ufile.io/jckwj

Maybe you can help me once again.

Best regards Uwe

junwu
Active Contributor
0 Kudos

"sap.app": {
"id":*******

did you put this id vlaue in the getmodulepath call?

pinakipatra
Contributor
0 Kudos

Hi Uwe,

if you look at the 404 error url it is pointing to ...ushell/resources/... to pickup the json file which I belief is wrong.

Try https://help.sap.com/viewer/40826922922346f890185c8ff02d30da/1.19/en-US/9c5a9619f69f4a819f91fc89d9ff...

in Component.js

or https://blogs.sap.com/2017/04/30/how-to-include-third-party-libraries-modules-in-sapui5/


BR

Pinaki


uwe_isenmann2
Participant
0 Kudos

Thank you for your Response.

I tried you coding but I'm not able to load the JSON file on the local SAP System.

In WebIde it works fine:

But on the local SAP system the URL is not correct:

Can anybody see what I'm doing wrong?

junwu
Active Contributor
0 Kudos

var path=jQuery.sap.getModulePath("youappiddefinedinmanifest","/model/AppData.json")

YOURJSONMODEL.loadData(path);