cancel
Showing results for 
Search instead for 
Did you mean: 

Issue with GWSAMPLE_BASIC/Business Partner Service

justin_kemp
Participant
0 Kudos

Hello

I am trying to implement POST operation with GWSAMPLE_BASIC and Business Partner Entity Set. Here is my code:

Init Method:

     self=this;

   var surl = "proxy/http/sapes4.sapdevcenter.com/sap/opu/odata/IWBEP/GWSAMPLE_BASIC/";

  var omodel = new sap.ui.model.odata.v2.ODataModel(surl,true);

  omodel.setDefaultBindingMode("TwoWay");

  sap.ui.getCore().setModel(omodel);

onPress: function()

  {

  var bpId = this.getView().byId("i1").getValue();

  var cname = this.getView().byId("i2").getValue();

  var tbl = self.getView().byId("idbp");

  var x =

     {

     "BusinessPartnerID": bpId,

     "CompanyName": cname,

     "EmailAddress":"abc@yahoo.com",

     "WebAddress":"http://www.google.com",

     "PhoneNumber":"+111111",

     "FaxNumber":"+111111",

     "LegalForm":"AG",

     "CurrencyCode":"USD",

     "BusinessPartnerRole":"01",

    

     "Address": {

      "City":"Chicago",

      "PostalCode":"60004",

      "Building":"47",

      "Street":"Rand Road",

      "Country":"US",

      "AddressType":"02",

          },

          }    ;

  var url = "proxy/http/sapes4.sapdevcenter.com/sap/opu/odata/IWBEP/GWSAMPLE_BASIC/";

  var method= "POST";

  var requestObj = {

  requestUri: '',

  method: '',

  headers: {

  "X-Requested-With": "XMLHttpRequest",

  "Content-Type": "application/json",

  "DataServiceVersion": "2.0",

  "MaxDataServiceVersion": "2.0",

  "Accept": "application/json"

  }  };

  requestObj.requestUri = url;

  requestObj.method = method;

  requestObj.data = x;

  OData.request(requestObj, function() {

  alert("Success");

  });

  },

Accepted Solutions (0)

Answers (2)

Answers (2)

justin_kemp
Participant
0 Kudos

I was still editing it clicked Saved by mistake.

View:

<content>

  <Input id="i1" value="" width="200px" />

  <Input id="i2" value="" width="200px" />

  <Button text="Add" press="onPress" />

  <Table id="idbp" items="{/BusinessPartnerSet}">

  <columns>

  <Column>

  <Text text="BusinessPartnerID" />

  </Column>

  <Column>

  <Text text="Company Name" />

  </Column>

  <Column>

  <Text text="City" />

  </Column>

  </columns>

  <items>

  <ColumnListItem>

  <cells>

  <Text text="{BusinessPartnerID}" />

  <Text text="{CompanyName}" />

  <Text text="{Address/City}" />

  </cells>

  </ColumnListItem>

  </items>

  </Table>

  </content>

I get an error: "datajs.js:17 POST http://localhost:60901/odata_post/proxy/http/sapes4.sapdevcenter.com/sap/opu/odata/IWBEP/GWSAMPLE_BA... 403 (Forbidden)"

I think GWSAMPLE_BASIC supports CRUD operation so POST should work. Is there anything wrong with code.

junwu
Active Contributor
0 Kudos

why not using model object?

justin_kemp
Participant
0 Kudos

I was using a tutorial to work on odata post method. It worked that way.

junwu
Active Contributor
0 Kudos

don't follow bad example....

justin_kemp
Participant
0 Kudos

Can you suggest how to correct it.

junwu
Active Contributor
0 Kudos

first check if update service is allowed for that service.

justin_kemp
Participant
0 Kudos

Yes, as per

  • CRUDQ operations for the entity types BusinessPartner, Contact, Product, SalesOrder, SalesOrderLineItem are allowed for GWSAMPLE_BASIC service
justin_kemp
Participant
0 Kudos

Made it work by calling model object.Thanks.

junwu
Active Contributor
0 Kudos

kindly mark correct answer...

junwu
Active Contributor
0 Kudos

then what?