$(function () { pageContext.i18n.modTalk = 'moderation talk'; pageContext.i18n.replyToComment = 'Reply'; pageContext.i18n.modTalkEmpty = 'moderation talk is empty'; pageContext.url.getModTalk = "/comments/%25ID%25/listModTalk.json"; pageContext.url.possibleCommentRecipients = "/comments/%ID%/possibleRecipients.json"; pageContext.url.commentEdit = '/comments/%25ID%25/edit.html'; pageContext.url.commentView = '/comments/%ID%/view.html'; pageContext.i18n.commentVisibility = { 'full': 'Viewable by all users', 'op': 'Viewable by the original poster', 'mod': 'Viewable by moderators', 'opAndMod': 'Viewable by moderators and the original poster', 'other': 'Advanced visibility', 'dialogTitle': 'Comment visibility', 'selectGroups': 'Visible to groups', 'selectOther': 'Other recipients', 'selectOriginalPoster': 'Original poster', 'selectModerators': 'Moderators', 'selectAssignees': 'Asked to answer users' }; pageContext.i18n.commentMenuLabels = { 'comment-edit': 'comments.menu.edit', 'comment-delete': 'comments.menu.delete', 'comment-convert': 'comments.menu.convert' };pageContext.i18n.answer= { bestAnswer: 'Best Answer', controlBar : { accept: 'Accept', unaccept: 'Unaccept', acceptCommand: 'Accept this answer as correct', cancelAcceptedCommand: 'Remove this answers accepted status' } }; window.croles = { u: false, op: false, m: false, og: false, as: false, ag: false, dc: false, doc: false, eo: false, ea: false }; tools.init({ q: { e: false, ew: false, eo: false, r: false, ro: false, d: false, dow: false, fv: false, c: false, co: false, p: false, tm: false , ms: false, mos: false }, n: { f: false, vf: false, vfo: false, vr: false, vro: false, c: false, co: false, vu: false, vd: false, w: false, wo: false, l: false }, c: { e: false, eo: false, d: false, dow: false, ta: false, tao: false, l: false }, a: { e: false, ew: false, eo: false, d: false, dow: false, a: false, aoq: false, ao: false, tc: false, tco: false, p: false, tm: false }, pc: croles }, { tc: true, nsc: true }); commandUtils.initializeLabels(); }); Skip to Content
0

How to read the values of JSON model from controller

Jan 04, 2017 at 10:32 AM

158

avatar image

Hi experts,

I am developing a UI5 application, and using json model to bind data.

Controller code :

var serviceURL = "/xxx/BBB/services.xsodata/USR_REF/?$format=json";

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

JsonModel.loadData(serviceURL);

this.getView().setModel(JsonModel, "UserConfigView");

I need to extract the value of each property from this Json Model

structure of JSON

{"d":

{"results": [

{ "__metadata":

{ "type":"XXXX.services.USR_REFType", "uri":"https://XXXXXXXX.hana.ondemand.com:443/XXXXXX/services.xsodata/USR_REF('22462245619163681')" }.

"USER_ID":"22462245619163681",

"USER_ID":"ABC",

"SALES_ORG":"1000",

"DIVISION":"00",

"DIST_CHANNEL":"10" }

] } }

How to extract the value of SALES_ORG within the controller ?.

Thanks,

Sandeep

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

4 Answers

Best Answer
Jun Wu Jan 04, 2017 at 02:56 PM
0

JsonModel.loadData(serviceURL,null,false);

JsonModel.getProperty("/d/results/0/SALES_ORG")

Share
10 |10000 characters needed characters left characters exceeded
Parth Jhalani Jan 04, 2017 at 11:38 AM
0

Hi Sandeep,

User below code

this.getView().getModel("UserConfigView").getProperty("/SALES_ORG");

Regards,

Parth

Show 1 Share
10 |10000 characters needed characters left characters exceeded

HI Parth,

Thanks for your reply.

I used same method to get the value , but its showing as 'undefined'.

Thanks,

Sandeep

0
Suman Baki Jan 04, 2017 at 12:01 PM
0

Hi Sandeep,

your service url is not working

Show 1 Share
10 |10000 characters needed characters left characters exceeded

Hi Suman,

It's an internal URL. and Its working properly here.

The problem is with reading the Json Model data in controller.

Thanks,

Sandeep

0
Parth Jhalani Jan 04, 2017 at 12:01 PM
0

Hi,

Please share your console screenshot. Also, share the code snippet.

Regards,

Parth

Show 3 Share
10 |10000 characters needed characters left characters exceeded

Hi Parth,

It's not throwing any error in console.

Code snippet is

	var serviceURL = "/XXX/YYY/services.xsodata/USR_REF/?$format=json";
        var JsonModel = new sap.ui.model.json.JSONModel();
        JsonModel.loadData(serviceURL);
        this.getView().setModel(JsonModel, "UserConfigView");
        var salesOrg = this.getView().getModel("UserConfigView").getProperty("/SALES_ORG");
0

after writing this.getView().getModel("UserConfigView") what you get share that console screen shot

0

what you post your json structure in that USER_ID is duplicate key

0