Skip to Content

Get first item of select box when page first loads


I have summary screen that must load accounts in a select box and populate all the fields in the form using oData and basing it on an ID in the URL.

But I need to load the select box in order to get the right account to load the rest of the page and the first account has to already be filled once page loads (so without anyone selecting in the the select box). I am only able to load the combo box after rendering and not onInit and I am not able to get the items of the select box in order to get the account number.

I am able to load the entire page if it is only ONE account and I am able to load all the account numbers in the select box but when the page is loaded then it is not based on the account number.

What is a better way to load the select box and be able to get the items in order to load the rest of the page?

Would getting the oData and turning into a json onInit be better? if so, can I get an example, I've tried some examples and have been unsuccessful.

onInit: function() {
//get URL and get ID from it
        var url = window.location.href;
        var id = url.substring(urlString.length - 10, urlString.length);
       $.sap.urlId = id;
//NOT WORKING: SAP Odata service url
    var sServiceUrl = "/SummaryScreenSet('" + id + "')";
    //Create OData model
    var oModel = new sap.ui.model.odata.v2.ODataModel(sServiceUrl, {
	useBatch: true});
    var oODataJSONModel = new sap.ui.model.json.JSONModel();
    var oData ="/SummaryScreenSet", {
	method: "GET",
	success: function(oData2, oResponse) {
	//Create JSON Model"Success!");
	oODataJSONModel.setData({modelData: oData2.results});},
	error: function(oError) {"Error!");}});

onAfterRendering: function() {
	var id = $.sap.urlId;
        var comboB = this.getView().byId("accountBox");
	comboB.bindAggregation("items", "/SummaryScreenSet", new sap.ui.core.ListItem({text: "{ACCOUNT}"}));
	var oFilterDist = new sap.ui.model.Filter("PARTNER", sap.ui.model.FilterOperator.EQ, id);
Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • May 03, 2018 at 06:15 AM

    Hi ..

    Few things to clarify .

    1. Why are you getting the id from the URL .

    2. If you are populating combobox on rendering than after the combobox gets populated or bind than call the rest of the page data you say it depends on the value of combobox data .. than why r you calling the service on Init



    Add comment
    10|10000 characters needed characters exceeded

    • Ok ..

      First of all .. making your app dependent to the url is not good .. you need to pass the value by some other means .. if its routing than pass it as routing parameter while calling the route function..

      Second once you passed the Id than on getting the Id call the function which gets other data .. or even you can the select box data service and bind it and make the selected key of selectbox to the passed Id on change event of binding.


  • May 04, 2018 at 08:39 AM


    Please bind the property "selectedKey" of combo box with path to view the default first value of the array. Here as an example I have used Countrycollection array and binded the first row of the array

    <ComboBox items="{ path: '/CountriesCollection', sorter: { path: 'text' } }"


    <core:Item key="{key}" text="{text}" />


    Add comment
    10|10000 characters needed characters exceeded