Skip to Content
May 02, 2018 at 04:11 PM

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);