cancel
Showing results for 
Search instead for 
Did you mean: 

I can not access the OData service from BAS.

Mahmood99
Explorer
0 Kudos
924

Hi,

As you can see, the ui5 app appears empty. Have someone an idea to solve this issue?

View

<table:Table id="table" selectionMode="Single" rows="{myODataModel>/ZEMPLOYEEDATASet}" enableColumnReordering="false">
                            <!-- columns for customer name, address, and email -->
                            <table:columns>
                                <table:Column id="idColumn3" width="50%">
                                    <table:label>
                                        <Label id="idLabel3" text="ID"/>
                                    </table:label>
                                    <table:template>
                                        <Text id="idText3" text="{myODataModel>Id}"/>
                                    </table:template>
                                </table:Column>
                                <table:Column id="idColumn1" width="20%">
                                    <table:label>
                                        <Label id="idLabel1" text="Name"/>
                                    </table:label>
                                    <table:template>
                                        <Text id="idText1" text="{myODataModel>Name}"/>
                                    </table:template>
                                </table:Column>
                                <table:Column id="idColumn2" width="30%">
                                    <table:label>
                                        <Label id="idLabel2" text="Address"/>
                                    </table:label>
                                    <table:template>
                                        <Text id="idText2"  text="{myODataModel>Address}"/>
                                    </table:template>
                                </table:Column>
                                <table:Column id="idColumn4" width="50%">
                                    <table:label>
                                        <Label id="idLabel4" text="Phone Number"/>
                                    </table:label>
                                    <table:template>
                                        <Text id="idText4" text="{myODataModel>phonenumber}"/>
                                    </table:template>
                                </table:Column>
                            </table:columns>
                        </table:Table>

controller

onInit: function () {
    // Wait for the view to fully render
    this.getView().addEventDelegate({
        onAfterRendering: function () {
            // OData model instance
            var oModel = new sap.ui.model.odata.v2.ODataModel("/sap/opu/odata/SAP/Z_EMPLOYEE_SRV/");
            this.getView().setModel(oModel);
            
            // Get the table instance
            var oTable = this.getView().byId("table");
            
            if (oTable) {
                // Bind the rows of the table to the OData entity set
                oTable.bindRows({
                    path: "/ZEMPLOYEEDATASet",  // OData entity set
                    parameters: {
                        select: "Id,Name,Address,Phonenumber"  // Select fields
                    }
                });
            } else {
                console.error("Table not found");
            }
        }.bind(this)
    });
}

manifest file

"sap.app": {
    ............
    .......
    "dataSources": {
      "mainService": {
          "uri": "/sap/opu/odata/SAP/Z_EMPLOYEE_SRV/",
          "type": "OData"
          
      }  
    }
  },
"sap.ui5": {
  "models": {
   .....
      "myODataModel": {
                "type": "sap.ui.model.odata.v2.ODataModel",
                "dataSource": "mainService",
                "settings": {
                    "defaultBindingMode": "TwoWay",
                    "defaultCountMode": "Inline"
                }
            }
    },
}

 

Mahmood99_1-1729153087759.pngMahmood99_2-1729153269636.png

Mahmood99_3-1729155112159.png

 

Thank you 
Mahmood

Accepted Solutions (0)

Answers (4)

Answers (4)

Marian_Zeis
Active Contributor

Can you please tell use why do use the onInit und AfterRendering anyway? You can just use the default model without any JavaScript Code.

To make it more simple you can just this in the xml view:

<table:Table id="table" selectionMode="Single" rows="{/ZEMPLOYEEDATASet}" enableColumnReordering="false">
    <!-- columns for customer name, address, and email -->
    <table:columns>
        <table:Column id="idColumn3" width="50%">
            <table:label>
                <Label id="idLabel3" text="ID"/>
            </table:label>
            <table:template>
                <Text id="idText3" text="{Id}"/>
            </table:template>
        </table:Column>
        <table:Column id="idColumn1" width="20%">
            <table:label>
                <Label id="idLabel1" text="Name"/>
            </table:label>
            <table:template>
                <Text id="idText1" text="{Name}"/>
            </table:template>
        </table:Column>
        <table:Column id="idColumn2" width="30%">
            <table:label>
                <Label id="idLabel2" text="Address"/>
            </table:label>
            <table:template>
                <Text id="idText2" text="{Address}"/>
            </table:template>
        </table:Column>
        <table:Column id="idColumn4" width="50%">
            <table:label>
                <Label id="idLabel4" text="Phone Number"/>
            </table:label>
            <table:template>
                <Text id="idText4" text="{phonenumber}"/>
            </table:template>
        </table:Column>
    </table:columns>
</table:Table>

 and in the manifest json make the OData Model the default like this and remove the name "myODataModel":

"sap.ui5": {
  "models": {
   .....
      "": {
                "type": "sap.ui.model.odata.v2.ODataModel",
                "dataSource": "mainService",
                "settings": {
                    "defaultBindingMode": "TwoWay",
                    "defaultCountMode": "Inline"
                }
            }
    },
}

 

Mahmood99
Explorer
0 Kudos
Hi Marian, thanks for your answer. I have updated the manifest and view files as you said but I still get this message "[ODataMetadata] initial loading of metadata failed."
Marian_Zeis
Active Contributor
0 Kudos
@Mahmood99 please check if the Service is reachable and if you have the correct rights to access it. Go to the network tab and check the response and also check TX /IWFND/ERROR_LOG in your system for errors
Mahmood99
Explorer
0 Kudos
In /IWFND/ERROR_LOG thereis no error. but in network tab I got "404 Not Found" and "Cannot GET /sap/opu/odata/SAP/Z_EMPLOYEE_SRV/$metadata"
junwu
SAP Champion
SAP Champion
0 Kudos

check your ui5.yaml file,  do you have something like this?

server:
customMiddleware:
- name: fiori-tools-proxy
afterMiddleware: compression
configuration:
ignoreCertError: true
backend:
- path: /sap
url: "https://******"

Mahmood99
Explorer
0 Kudos

server:

   customMiddleware:

     - name: fiori-tools-proxy

      afterMiddleware: compression

         configuration:

                ignoreCertError: true

               ui5:

                path:

            - /resources

             - /test-resources

            url: https://ui5.sap.com

junwu
SAP Champion
SAP Champion
0 Kudos
you miss this part backend: - path: /sap url: "https://******"
Mahmood99
Explorer
0 Kudos
I have added this part but it still does not work
junwu
SAP Champion
SAP Champion
0 Kudos
Show me what you did
Mahmood99
Explorer
0 Kudos

server:

customMiddleware:

- name: fiori-tools-proxy

afterMiddleware: compression configuration:

ignoreCertError: true

ui5: path:

- /resources

- /test-resources

url: https://ui5.sap.com

backend: 

- path: /sap

url: "http://....8000" # SAP system URL from the image

junwu
SAP Champion
SAP Champion
0 Kudos

your table already has binding, why you do the binding in your controller again?

Mahmood99
Explorer
0 Kudos
Hi, I just wanted to try it from the controller. I have commented onInit function first but nothing has been changed. the same issue..
smarchesini
SAP Champion
SAP Champion
0 Kudos

Hello @Mahmood99 ,

Here the application does not know where is from your oData service. 
If it's an external one, you should define the model in this way:
var oModel = new ODataModel("http://services.odata.org/Northwind/Northwind.svc/");
But you will have a security issue, and you need to change your configuration files. 

The best approach as I see you are using the manifest, is to define the destination. 
Here some blog and answers can help you: