$(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: true, vro: true, 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
avatar image
Former Member

How to read the values of JSON model from controller

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

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

4 Answers

  • Best Answer
    Jan 04, 2017 at 02:56 PM

    JsonModel.loadData(serviceURL,null,false);

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

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jan 04, 2017 at 11:38 AM

    Hi Sandeep,

    User below code

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

    Regards,

    Parth

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      HI Parth,

      Thanks for your reply.

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

      Thanks,

      Sandeep

  • avatar image
    Former Member
    Jan 04, 2017 at 12:01 PM

    Hi Sandeep,

    your service url is not working

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      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

  • avatar image
    Former Member
    Jan 04, 2017 at 12:01 PM

    Hi,

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

    Regards,

    Parth

    Add comment
    10|10000 characters needed characters exceeded