Skip to Content

Unauthorized triying to consume odata

Hi i don't know where can i start i have adialog that opens at the beginning to introduce an user and made a query (the odata works propertly i already tested it in sap getaway with something like this /sap/opu/odata/sap/ZERP_ACTIVIDADES_SRV/ReservaSet?$filter=Asesor eq '10000324') that odata was made in the back end and in the front i add that service with the tx /n/IWFND/MAINT_SERVICE.

In my code of my controller (the app is very simple but...):

onInit: function(){ 
		    this.oDialog();
		},
		
		oDialog : function () {
	         var oView = this.getView();
	         var oDialog = oView.byId("userDialog");
	         // create dialog lazily
	         if (!oDialog) {
	            // create dialog via fragment factory
	            oDialog = sap.ui.xmlfragment(oView.getId(), "Calendario.app.view.Popup_usuario", this);
	            oView.addDependent(oDialog);
	         }

	         oDialog.open(); // Abrimos el dialogo
	      },
	      
	      getText: function(){
	    		//Obtenemos el texto
	    		var asesor = this.getView().byId("usuario").getValue();
	    		
	    	        //Hacemos la peticion al odata
	    	        this.makeRequest(asesor).then(function(oData){
	    	        	var someModel = new sap.ui.model.json.JSONModel();
	    	        	someModel.setData(oData);
	    	        	this.getView().setModel(someModel, "");
	    	        });
	    		//Close
	    		this.getView().byId('userDialog').close();
	    	},
	    	
	    	closeDialog: function(){
	    		this.getView().byId('userDialog').close();
	    	},
	    	
	    	makeRequest: function(sAsesor){
		    	return new Promise(function(resolve, reject) {
		    	    var oModel = new sap.ui.model.odata.ODataModel({
		    		serviceUrl: "https://client.com:port/sap/opu/odata/sap/ZERP_ACTIVIDADES_SRV",
		    	        json: true
		    	    });
		    	    var sPath = "/ENDPOINT?filter=search eq " + sAsesor;
		    	    oModel.read(sPath, null, null, true,
		    	       function(oData) {
		    		  resolve(oData);
		    	       },
		    	       function(oError) {
		    		  reject(oError);
		    		});
		    	});
	    	}

my view

				<Panel id="panel-id">
				<FlexBox 	alignItems="Start"
							justifyContent="Center">
						<items>
							<Table 	 id="tabla"
									 items="{ path : '/ReservaSet' }" 
									 fixedLayout="true"
									 popinLayout="Block">
							<columns>
								<Column  width="12em">
									<Text text="Sucursal" />
								</Column>
								
								<Column  width="12em">
									<Text text="Nombre de Cliente" />
								</Column>
							</columns>
							
							
							<items>
							
								<ColumnListItem>
									<cells>
										<ObjectIdentifier
											text="{Sucursal}"/>
										<Text text="{CliNombre}" />
									</cells>
								</ColumnListItem>
							
							</items>
							
							</Table>
						</items>
					</FlexBox>
				</Panel>

and i'm getting so many erros, im using a chrome extension called CORS to allow control origin

i can see my odata in the browser but i don't know what do i need to check

errors.png (66.9 kB)
Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • Best Answer
    Mar 14 at 12:54 PM

    Thanks to Jun Wu , deploy the aplication to avoid those errors and i change the request a little:

    this is the event that it is open when press ok on the dialog:

    	      getText: function(){
    	    		//Obtenemos el texto
    	    		var asesor = this.getView().byId("usuario").getValue();
    	    		var oTable = this.getView().byId("tabla");
    	    		var sURI = "/sap/opu/odata/SAP/ZERP_ACTIVIDADES_SRV";
    	    		var oDataModel = new ODataModel(sURI, true);
    	    		var oModel = new sap.ui.model.json.JSONModel();
    	    		var oFilter = new Filter("Asesor", "EQ", asesor);
    	    		oDataModel.read("/ReservaSet", {
    	    			filters: [oFilter],
    	    			success: function(oData, response) {
    	    	        var oResults = oData.results;
    	    	        oModel.setData(oData.results);
    	    	        oTable.setModel(oModel);
    	    	        
    	    			 }
    	            });
    
    	    		//Close
    	    		this.getView().byId('userDialog').close();
    	    		MessageToast.show(asesor);
    	    	},
    <br>
    Add comment
    10|10000 characters needed characters exceeded

  • Mar 13 at 12:22 AM

    deploy to abap server to run your app

    Add comment
    10|10000 characters needed characters exceeded

    • hello, thanks for you reply . i did the deploy and when i send the user get this error:

      jquery.sap.global-dbg.js:1035 2018-03-13 09:05:48.937699 The following problem occurred: HTTP request failed404,Not Found,{"error":{"code":"005056A509B11EE1B9A8FEC11C21D78E","message":{"lang":"es","value":"Resource not found for the segment 'ENDPOINT'."},"innererror":{"transactionid":"2B097E0A03924EAAB80D2A1B9EC7A672","timestamp":"20180313120550.0044190","Error_Resolution":{"SAP_Transaction":"For backend administrators: run transaction /IWFND/ERROR_LOG on SAP Gateway hub system and search for entries with the timestamp above for more details","SAP_Note":"See SAP Note 1797736 for error analysis (https://service.sap.com/sap/support/notes/1797736)"}}}} -

      i run the /IWFND/ERROR_LOG so i see this:

      The url of the request or metadata definition are incorrect.

      maybe is the url that i pass to the odata?

      	    	makeRequest: function(sAsesor){
      		    	return new Promise(function(resolve, reject) {
      		    	    var oModel = new sap.ui.model.odata.ODataModel({
      		    		serviceUrl: "/sap/opu/odata/sap/ZERP_ACTIVIDADES_SRV",
      		    	        json: true
      		    	    });
      		    	    var sPath = "/ENDPOINT?filter=search eq " + sAsesor;
      		    	    oModel.read(sPath, null, null, true,
      		    	       function(oData) {
      		    		  resolve(oData);
      		    	       },
      		    	       function(oError) {
      		    		  reject(oError);
      		    		});
      		    	});
      	    	}
      

      i want to build something like this /sap/opu/odata/sap/ZERP_ACTIVIDADES_SRV/ReservaSet?$filter=Asesor eq 'user pass in the app example: 10000324' i tried like this to test my odata and it works so i don't know if i made a mistake passing the url

      tueday-error.png (34.0 kB)
  • Mar 13 at 05:19 PM
    var sPath = "/ENDPOINT?filter=search eq " + sAsesor;

    why you put ENDPOINT here?

    Add comment
    10|10000 characters needed characters exceeded