<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>Question Re: UI5 Set/Get a Global model in Technology Q&amp;A</title>
    <link>https://community.sap.com/t5/technology-q-a/ui5-set-get-a-global-model/qaa-p/455375#M70592</link>
    <description>&lt;P&gt;Okay, but what do you think the syntax for the code within the controller should be?. &lt;/P&gt;&lt;P&gt;Obviously this code&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt; var oModel1 = this.getModel("oModelTest"); 

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;will not work because &lt;STRONG&gt;this&lt;/STRONG&gt; is not pointing at the component. &lt;/P&gt;&lt;P&gt;And I'm pretty sure I can't use the code shown below either, as it does not make sense: &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;var oModel1 = getView().getModel("oModelTest");

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;So how does one reference the model set within the component?. &lt;/P&gt;</description>
    <pubDate>Thu, 23 Mar 2017 14:13:09 GMT</pubDate>
    <dc:creator>gary_king2</dc:creator>
    <dc:date>2017-03-23T14:13:09Z</dc:date>
    <item>
      <title>UI5 Set/Get a Global model</title>
      <link>https://community.sap.com/t5/technology-q-a/ui5-set-get-a-global-model/qaq-p/455372</link>
      <description>&lt;P&gt;I have read a few articles on using a Global model, and, there seem to be a number of ways of doing this, some right and some wrong. I'm avoiding defining my model in manifest at present and opting to define it directly in the component.js.  The code I'm using is as follows:&lt;/P&gt;&lt;P&gt; Within the component.js onInit:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;//var oModel1 = new sap.ui.model.json.JSONModel("model/Testmodel.json");
var oData = { Test : { name : "World" }	};
var oModel1 = new sap.ui.model.json.JSONModel(oData);
sap.ui.getCore().setModel(oModel1,"oModelTest");
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt; And in my View Controller.js I have the following code within the onInit function:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;var oModel = sap.ui.getCore().getModel("oModelTest");&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt; However, oModel is showing as undefined when monitoring in debug. It does not error though. I have also tried using the variable oModel1 as someone mentioned that name should be the same at both ends of the set/get. But alas the same issue. &lt;/P&gt;&lt;P&gt;Someone mentioned that ideally we should not use the core to set/get the global model. I am intrigued to see how I can get this working, and if possible without using the core.&lt;/P&gt;&lt;P&gt;If anyone has this working I would greatly appreciate some demonstration code. &lt;/P&gt;&lt;P&gt;Best regards &lt;/P&gt;</description>
      <pubDate>Thu, 23 Mar 2017 11:06:31 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/ui5-set-get-a-global-model/qaq-p/455372</guid>
      <dc:creator>gary_king2</dc:creator>
      <dc:date>2017-03-23T11:06:31Z</dc:date>
    </item>
    <item>
      <title>Re: UI5 Set/Get a Global model</title>
      <link>https://community.sap.com/t5/technology-q-a/ui5-set-get-a-global-model/qaa-p/455373#M70590</link>
      <description>&lt;P&gt;I managed to get a solution working, but to be honest I'm not happy about using the core. Here's what I have working. &lt;/P&gt;&lt;P&gt;In the component.js&lt;/P&gt;&lt;P&gt;//Test model&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;//Test model
var oData = { Test : { name : "World" }	};
var oModel1 = new sap.ui.model.json.JSONModel(oData);
sap.ui.getCore().setModel(oModel1,"oModelTest");
sap.ui.core.UIComponent.prototype.init.apply(this);
//Show in console
console.log(sap.ui.getCore().getModel("oModelTest"));
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;And in my controller, I have: &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;var oModel1 = sap.ui.getCore().getModel("oModelTest").getProperty("/Test");&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt; This now works, but as mentioned, I would like to avoid using the core.&lt;/P&gt;&lt;P&gt;Anyone?&lt;/P&gt;</description>
      <pubDate>Thu, 23 Mar 2017 12:16:27 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/ui5-set-get-a-global-model/qaa-p/455373#M70590</guid>
      <dc:creator>gary_king2</dc:creator>
      <dc:date>2017-03-23T12:16:27Z</dc:date>
    </item>
    <item>
      <title>Re: UI5 Set/Get a Global model</title>
      <link>https://community.sap.com/t5/technology-q-a/ui5-set-get-a-global-model/qaa-p/455374#M70591</link>
      <description>&lt;P&gt;your code looks ok. but usually we don't use core....&lt;/P&gt;&lt;P&gt;in component.js. this.setModel,  this stored model will be available to all view.&lt;/P&gt;</description>
      <pubDate>Thu, 23 Mar 2017 12:21:32 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/ui5-set-get-a-global-model/qaa-p/455374#M70591</guid>
      <dc:creator>junwu</dc:creator>
      <dc:date>2017-03-23T12:21:32Z</dc:date>
    </item>
    <item>
      <title>Re: UI5 Set/Get a Global model</title>
      <link>https://community.sap.com/t5/technology-q-a/ui5-set-get-a-global-model/qaa-p/455375#M70592</link>
      <description>&lt;P&gt;Okay, but what do you think the syntax for the code within the controller should be?. &lt;/P&gt;&lt;P&gt;Obviously this code&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt; var oModel1 = this.getModel("oModelTest"); 

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;will not work because &lt;STRONG&gt;this&lt;/STRONG&gt; is not pointing at the component. &lt;/P&gt;&lt;P&gt;And I'm pretty sure I can't use the code shown below either, as it does not make sense: &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;var oModel1 = getView().getModel("oModelTest");

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;So how does one reference the model set within the component?. &lt;/P&gt;</description>
      <pubDate>Thu, 23 Mar 2017 14:13:09 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/ui5-set-get-a-global-model/qaa-p/455375#M70592</guid>
      <dc:creator>gary_king2</dc:creator>
      <dc:date>2017-03-23T14:13:09Z</dc:date>
    </item>
    <item>
      <title>Re: UI5 Set/Get a Global model</title>
      <link>https://community.sap.com/t5/technology-q-a/ui5-set-get-a-global-model/qaa-p/455376#M70593</link>
      <description>&lt;P&gt;just this.getmodel, they will find it.&lt;/P&gt;</description>
      <pubDate>Thu, 23 Mar 2017 14:20:58 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/ui5-set-get-a-global-model/qaa-p/455376#M70593</guid>
      <dc:creator>junwu</dc:creator>
      <dc:date>2017-03-23T14:20:58Z</dc:date>
    </item>
    <item>
      <title>Re: UI5 Set/Get a Global model</title>
      <link>https://community.sap.com/t5/technology-q-a/ui5-set-get-a-global-model/qaa-p/455377#M70594</link>
      <description>&lt;P&gt;try&lt;BR /&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;this.getOwnerComponent().getModel("oModelTest")&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 24 Mar 2017 06:45:09 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/ui5-set-get-a-global-model/qaa-p/455377#M70594</guid>
      <dc:creator>former_member227918</dc:creator>
      <dc:date>2017-03-24T06:45:09Z</dc:date>
    </item>
    <item>
      <title>Re: UI5 Set/Get a Global model</title>
      <link>https://community.sap.com/t5/technology-q-a/ui5-set-get-a-global-model/qaa-p/455378#M70595</link>
      <description>&lt;P&gt;use this.getView().setModel(ModelName, "ModelName") &lt;/P&gt;</description>
      <pubDate>Fri, 24 Mar 2017 11:14:29 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/ui5-set-get-a-global-model/qaa-p/455378#M70595</guid>
      <dc:creator>karthikarjun</dc:creator>
      <dc:date>2017-03-24T11:14:29Z</dc:date>
    </item>
    <item>
      <title>Re: UI5 Set/Get a Global model</title>
      <link>https://community.sap.com/t5/technology-q-a/ui5-set-get-a-global-model/qaa-p/455379#M70596</link>
      <description>&lt;P&gt;Yes, I have used that within the component, but, when I then attempt to retrieve the model in the controller using .getModel it does not retrieve anything. &lt;/P&gt;&lt;P&gt;We have also tried to define a model (global) within the manifest, but we seem to hit the same issue that we always  hit whenever we attempt to load a json file, in that it fails. Well, it does not fail, but gives a 404 error. We've tried:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;oModel1.loadData("model/Testmodel.json");
oModel1.loadData("Testmodel.json");
var oModel1 = new sap.ui.model.json.JSONModel("Testmodel.json";
var oModel1 = new sap.ui.model.json.JSONModel("model/Testmodel.json");
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;And obviously my json file is in the model subdirectory and called Testmodel.json. I have LINT checked the json file and that's free from error, so it's not that. It's something to with the resources. We are using eclipse as our IDE. &lt;/P&gt;</description>
      <pubDate>Fri, 24 Mar 2017 12:46:11 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/ui5-set-get-a-global-model/qaa-p/455379#M70596</guid>
      <dc:creator>gary_king2</dc:creator>
      <dc:date>2017-03-24T12:46:11Z</dc:date>
    </item>
    <item>
      <title>Re: UI5 Set/Get a Global model</title>
      <link>https://community.sap.com/t5/technology-q-a/ui5-set-get-a-global-model/qaa-p/455380#M70597</link>
      <description>&lt;P&gt;Please don't use "sap.ui.getCore().getModel()". Instead define the model in your manifest. You can access all the models from the manifest in the controller of each view by using "this.getOwnerComponent().getModel()" &lt;/P&gt;&lt;P&gt;In the each controller you can also create additional models with "this.getView().setModel()" and "this.getView().getModel()".&lt;/P&gt;&lt;P&gt;Hope it helps.&lt;/P&gt;&lt;P&gt;Kind regards,&lt;/P&gt;&lt;P&gt;Wouter&lt;/P&gt;</description>
      <pubDate>Sat, 25 Mar 2017 19:57:49 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/ui5-set-get-a-global-model/qaa-p/455380#M70597</guid>
      <dc:creator>WouterLemaire</dc:creator>
      <dc:date>2017-03-25T19:57:49Z</dc:date>
    </item>
    <item>
      <title>Re: UI5 Set/Get a Global model</title>
      <link>https://community.sap.com/t5/technology-q-a/ui5-set-get-a-global-model/qaa-p/455381#M70598</link>
      <description>&lt;P&gt;why this is the answer????&lt;/P&gt;</description>
      <pubDate>Sun, 26 Mar 2017 01:22:13 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/ui5-set-get-a-global-model/qaa-p/455381#M70598</guid>
      <dc:creator>junwu</dc:creator>
      <dc:date>2017-03-26T01:22:13Z</dc:date>
    </item>
    <item>
      <title>Re: UI5 Set/Get a Global model</title>
      <link>https://community.sap.com/t5/technology-q-a/ui5-set-get-a-global-model/qaa-p/455382#M70599</link>
      <description>&lt;P&gt;Can you share your code in plunkr.co please?&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;var oModel1 = new sap.ui.model.json.JSONModel("Testmodel.json"; // Close the bracket



&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;To get model data from view, use this.getView().getModel("MODELNAME") [with the same view-&amp;gt; controller]&lt;/P&gt;&lt;P&gt;outside or other controller-&amp;gt; use this.getView().byId("ID").getModel("ModelName")&lt;/P&gt;</description>
      <pubDate>Mon, 27 Mar 2017 13:15:28 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/ui5-set-get-a-global-model/qaa-p/455382#M70599</guid>
      <dc:creator>karthikarjun</dc:creator>
      <dc:date>2017-03-27T13:15:28Z</dc:date>
    </item>
    <item>
      <title>Re: UI5 Set/Get a Global model</title>
      <link>https://community.sap.com/t5/technology-q-a/ui5-set-get-a-global-model/qaa-p/455383#M70600</link>
      <description>&lt;P&gt;As mentioned, I really did not want to use the core: for creating the global model. We initially had issues loading a json file from the manifest, and as you can see I raised a question about 'why I could not load a json file', but have finally managed to resolve that issue, and so can now load my json model from the manifest as you have suggested. This was what I always had planned to do, just could not initially do it because of loading issues. &lt;/P&gt;&lt;P&gt;My next task is to find out how I can define the model based on metadata from an oData call. I have read somewhere that this can be done, but the article did not go into details. &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Mar 2017 14:02:24 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/ui5-set-get-a-global-model/qaa-p/455383#M70600</guid>
      <dc:creator>gary_king2</dc:creator>
      <dc:date>2017-03-27T14:02:24Z</dc:date>
    </item>
    <item>
      <title>Re: UI5 Set/Get a Global model</title>
      <link>https://community.sap.com/t5/technology-q-a/ui5-set-get-a-global-model/qaa-p/455384#M70601</link>
      <description>&lt;P&gt;You can also add an odata based model in the manifest.json. It's very easy with the UI editor of the manifest. The component.js will then automatically initialize the model.&lt;/P&gt;&lt;P&gt;Kr,&lt;/P&gt;&lt;P&gt;Wouter&lt;/P&gt;</description>
      <pubDate>Tue, 28 Mar 2017 17:18:50 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/ui5-set-get-a-global-model/qaa-p/455384#M70601</guid>
      <dc:creator>WouterLemaire</dc:creator>
      <dc:date>2017-03-28T17:18:50Z</dc:date>
    </item>
    <item>
      <title>Re: UI5 Set/Get a Global model</title>
      <link>https://community.sap.com/t5/technology-q-a/ui5-set-get-a-global-model/qaa-p/455385#M70602</link>
      <description>&lt;P&gt;In this case, how do you access the model from the browser console for debugging purposes? `this` refers to the browser window.&lt;/P&gt;</description>
      <pubDate>Tue, 04 Feb 2020 13:45:43 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/ui5-set-get-a-global-model/qaa-p/455385#M70602</guid>
      <dc:creator>former_member214732</dc:creator>
      <dc:date>2020-02-04T13:45:43Z</dc:date>
    </item>
    <item>
      <title>Re: UI5 Set/Get a Global model</title>
      <link>https://community.sap.com/t5/technology-q-a/ui5-set-get-a-global-model/qaa-p/13611156#M4818950</link>
      <description>this.getOwnerComponent().setModel(oModel,"myModel") and this.getOwnerComponent().getModel("myModel")</description>
      <pubDate>Tue, 20 Feb 2024 09:26:30 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/ui5-set-get-a-global-model/qaa-p/13611156#M4818950</guid>
      <dc:creator>1-Mar</dc:creator>
      <dc:date>2024-02-20T09:26:30Z</dc:date>
    </item>
    <item>
      <title>Re: UI5 Set/Get a Global model</title>
      <link>https://community.sap.com/t5/technology-q-a/ui5-set-get-a-global-model/qaa-p/13611160#M4818952</link>
      <description>and this.setModel(...) inside the Component.js will set the model on the Component directly. Therefore, the model is visible in all views inside that Component.</description>
      <pubDate>Tue, 20 Feb 2024 09:27:23 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/ui5-set-get-a-global-model/qaa-p/13611160#M4818952</guid>
      <dc:creator>1-Mar</dc:creator>
      <dc:date>2024-02-20T09:27:23Z</dc:date>
    </item>
    <item>
      <title>Re: UI5 Set/Get a Global model</title>
      <link>https://community.sap.com/t5/technology-q-a/ui5-set-get-a-global-model/qaa-p/14081720#M4911197</link>
      <description>&lt;P&gt;Now that sap.ui.getCore().getModel is deprecated, how do we achieve this when we want to set a model from a library, not an application?&lt;/P&gt;&lt;P&gt;We have a usecase where we have a utility method in a library that gets called by consuming apps. This utility is supposed to set a model that can be commonly used by all apps consuming this library. There is no Component.js or manifest here to call `this.getOwnerComponent.getModel(modelName)`.&lt;/P&gt;&lt;P&gt;Any suggestions?&lt;/P&gt;</description>
      <pubDate>Mon, 21 Apr 2025 04:03:25 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/ui5-set-get-a-global-model/qaa-p/14081720#M4911197</guid>
      <dc:creator>kavya-b</dc:creator>
      <dc:date>2025-04-21T04:03:25Z</dc:date>
    </item>
  </channel>
</rss>

