cancel
Showing results for 
Search instead for 
Did you mean: 

How to fill a JSON model from an MII Query Template

alan_myers
Explorer
0 Kudos
519

Hi,

I have a UI% select dropdown that I populate from a static JSON model. Can anyone point me to some documentation on how to change this to populate the JSON model from an MII Query Template please? I have spent days looking at forum sites and experimenting, but have not even come close to getting it to work.

My JSON code looks like this:

oSelect.setModel(new JSONModel({
selectedKey: "A2",
options: [{
key: "A1", text: "Peter" }, {
key: "A2", text: "Gill"}, {
key: "B1", text: "Harry"}, {
key: "B2", text: "Ralph"}, {
key: "C1", text: "Jack"}, {
key: "C2", text: "Jill"}, {
key: "D1", text: "Harry"}, {
key: "D2", text: "Sally"}
]
}));

Cheers, Alan

Accepted Solutions (1)

Accepted Solutions (1)

Kevin_Hunter
Product and Topic Expert
Product and Topic Expert

Hi Alan,

The MII Query template is going to return the data in XML so have you looked at the "XML to JSON" action block (Its in the "XML Functions" group at the very bottom of the Actions list ?

Thanks

Kevin

alan_myers
Explorer
0 Kudos

Thanks for the suggestion Kevin, It had not occurred to me to call in MII tx from my irpt to do the JSON load. I will have a play today

Kevin_Hunter
Product and Topic Expert
Product and Topic Expert
0 Kudos

No problem, another couple of ideas for you.

Combine your query and json conversion into a single transaction and just call the transaction. Or you could use a javascript library in your irpt such as XML2JSON. Or since you are using UI5 you could use an XML model rather than a JSON model - check this Blog.

Thanks

Kevin

alan_myers
Explorer
0 Kudos

Thanks Kevin, that gave me the final piece for the puzzle - setting path for the select binding to '/Rowsets/Rowset/0/Row' instead of '/options',

so my JSON instantiation became:

var my_Model = new sap.ui.model.json.JSONModel();
var my_URL = "/XMII/Illuminator?QueryTemplate=qryTemplateName&Content-Type=text/json&Param.1="+varParam1;
my_Model.loadData(my_URL, '', false, "POST");

and I add it to the Select object with:

oSelect.setModel(my_Model);

Answers (1)

Answers (1)

alan_myers
Explorer
0 Kudos

In case anyone stray across this question, here is my working solution, thanks to the guidance from Kevin and some other blogs.

.....

var my_Model = new sap.ui.model.json.JSONModel();
var my_URL = "/XMII/Illuminator?QueryTemplate=qryTemplateName&Content-Type=text/json&Param.1="+varParam1;
my_Model.loadData(my_URL, '', false, "POST");

.........

sap.ui.define(['sap/m/Select', 'sap/ui/core/Item', 'sap/ui/model/json/JSONModel'],
function (Select, Item, JSONModel) {
var oSelect = new Select({
selectedKey: 'keyvalue1',
items: {
path: '/Rowsets/Rowset/0/Row',
template: new Item({
key: '{keyFieldName}',
text: '{testFieldName}'
}),
},
change: function (oEvent) {
var selectedItem = oEvent.getParameter("selectedItem");
if (selectedItem) {
Selected_Text = selectedItem.getText();
Selected_Key = selectedItem.getKey();
alert(Selected_Key+'-'+Selected_Text);
}
}
});

oSelect.setModel(my_Model);
oSelect.placeAt('div1');

});