cancel
Showing results for 
Search instead for 
Did you mean: 

Consume URL in SAPUI5 application

former_member193103
Participant
0 Kudos

Hi Experts,

I am trying to develop a list using JSON model which, gets the data from SAP in the form of URL which is shared by one of my co-league. I have tested the same URL on my chrome browser, it renders the data in JSON format, which I need to populate on list screen of UI5. Could anyone of you help me to consume this shared URL in my SAPUI5 application.

Thanks and Regards

Himadri Jyoti

Accepted Solutions (1)

Accepted Solutions (1)

qmacro
Developer Advocate
Developer Advocate
0 Kudos

When you say "Could anyone of you help me to consume this shared URL in my SAPUI5 application" what exactly do you mean? Is it that you're getting an error? What is happening? Can you share your code ()?

Here's what I can remark so far:

- the URL of your service doesn't look like it's OData, so you are correct to use a JSON model

- using $ajax to pull in data in UI5 is a bad code smell, you don't need to do that (as intimated elsewhere in the comments here)

- if it's not an error, what help are you after, exactly? Are you asking us to write the code for you, or is it something else?

Thanks

dj

former_member193103
Participant
0 Kudos

Hi DJ,

I have coded this much till now

In Contoller.js

onInit: function() {

  var url = 'http://vpides.abcdef.in:8000/sap/bc/ztransport/VPIK900331/as4user/';

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

  

  $.ajax({

            url : url ,

            success: function(data,textStatus,jqXHR) {

            data = JSON.parse(data);

            console.log(data);   

                model.setData({modelData : data});

             

            },

          

      });

  sap.ui.getCore().setModel(model);

        

          

  },

In View.js

createContent : function(oController) {

  var list = new sap.m.List({

       headerText: "Products",

       items: {

         path: "/KEY",

       

         template: new sap.m.ObjectListItem({

           title : "{TRKORR}",

           number :  "{TRFUNCTION}",

                attributes : [

              new sap.m.ObjectAttribute({

               text : "{TRSTATUS}"

             }),

             new sap.m.ObjectAttribute({

               text : "{TARSYSTEM}"

             }),

             new sap.m.ObjectAttribute({

               text : "{KORRDEV}"

             }),

             new sap.m.ObjectAttribute({

               text : "{AS4USER}"

             }),

             new sap.m.ObjectAttribute({

               text : "{AS4DATE}"

             }),

             new sap.m.ObjectAttribute({

               text : "{AS4TIME}"

             }),

             new sap.m.ObjectAttribute({

               text : "{STRKORR}"

             })

             ]

         })      }

     });

  return new sap.m.Page({

  title: "Title",

  content: [list]

  });

  }

});

In the browser console I get this JSON format data like below

{"KEY":[{"TRKORR":"VPIK900331","TRFUNCTION":"K","TRSTATUS":"D","TARSYSTEM":"VPQ","KORRDEV":"SYST","AS4USER":"HEMENDRA_S","AS4DATE":"20130912","AS4TIME":"133633","STRKORR":""}]}

Now I want to populate this data into my list. But in the output screen it is not displaying anything.

I also attached the screen shot of console JSON data.

Thanks

Himadri

former_member184867
Active Contributor
0 Kudos

Please use model.setData( data ) instead of model.setData({modelData : data}).

former_member193103
Participant
0 Kudos

Hi Atanu,

Thanks a lot. It works..

Thanks and Regards

Himadri

Former Member
0 Kudos

Hi,

I am using this document (http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/907ae317-cb47-3210-9bba-e1b5e70e5...) to implement CrossAppNavigation intent.

I am receiving correctly the "componentData" on my destination app, but I can't figure how to tell the app to open a particular view (Detail view) to present the received ID 's data.

I'd like to ask if anyone already got something like that working...do you think in need to create the model inside the Component.js and then call the Detail view?

Many thanks,

Marc

Answers (6)

Answers (6)

Former Member
0 Kudos

Hey have you added the list to your HTML?

I mean into a div or someting?

myList.placeAt("myDiv");

former_member184867
Active Contributor
0 Kudos

Hi Himadri ,

I think the URL that you are using is a not an OData service URL , and this URL gives you a JSON Data.Then 1. You can directly create the JSON Model by Passing the URL in the constructor of sap.ui.model.json.JSONModel.  May be you can refer to SAPUI5 SDK - Demo Kit . 2. Then you need to set the model for the application. 3.Next you need to call bindItems() of List with the path to the data.

Regards,

Atanu

Former Member
0 Kudos

Hi Himadri,

Check out this link.

Here i have expalined how to read data from a Gateway service using AJAX and JSON Model.

Regards,

Sharique

surendra_pamidi
Contributor
0 Kudos

Hi Himadri,

Use Ajax get JSON to get the json data and set the data to model.

$.getJSON("jsonurl",function(){

model.setData({

data:data.d.results;

});

//operations on json data

});

Former Member
0 Kudos

After creating the model, do

model.loadData(yourURL); // to load data to the model

sap.ui.getCore().setModel(model);  // setting the model to the core

If data is not getting loaded due to same origin policy, try closing all your chrome instances and start your chrome in "--disable-web-security" mode!

former_member189929
Participant
0 Kudos

Hi Himadri,

Use below code

var oModel = new sap.ui.model.odata.ODataModel("/sap/opu/odata/sap/Ztransport/");

  oModel.read('/VPIK900331/as4user', null, null, true, function(oData, oResponse){

     //alert("Read successful: " + JSON.stringify(oData));

   },function(){

     alert("Read failed");});

     sap.ui.getCore().setModel(oModel);