cancel
Showing results for 
Search instead for 
Did you mean: 

post method for odata

former_member257196
Participant
0 Kudos

hi experts,

am posting odata to generate sales order but the sales order is creating double times

please help me in solving this problem

thank you

Accepted Solutions (0)

Answers (1)

Answers (1)

SergioG_TX
Active Contributor
0 Kudos

Madhu..

please share the code you have used...

former_member257196
Participant
0 Kudos

onCreateOrderPress:function(){

//var Enav;

debugger;

//var flag1 = '0';

var idShipToParty = this.getView().byId("idShipToParty").mProperties;

var idDocumentType = this.getView().byId("idDocumentType").mProperties;

var idPlant = this.getView().byId("idPlant").mProperties;

console.log(idShipToParty+idDocumentType+idPlant);

 

oData = {

     DistributionChnl : "10",

     Division : "20",

     DocumentType : idDocumentType['text'],

     Materialnumber : "FGDSDOLA0050",

     Plant : idPlant['text'],

     SalesOrganization : "1100",

     ShipToParty : idShipToParty['text'],

     SoldToParty : idShipToParty['text']

         };

this.onSuccess(oData);

sap.m.MessageBox.show(

      "Are you sure you want to create order.", {

          icon: sap.m.MessageBox.Icon.QUESTION,

          title: "Create Order",

          actions: [sap.m.MessageBox.Action.YES, sap.m.MessageBox.Action.NO],

          onClose: function(oAction) {

           if(oAction=="YES"){

          

           debugger;

           flag = true;

           OData.request

                 ({ 

                

                      requestUri: "proxy/http/xxxxx.xxxxx.net:8000/sap/opu/odata/sap/ZO_DOCU_SRV", 

                            method: "GET", 

                            headers: 

                                {      

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

           "Content-Type": "application/atom+xml",

         "DataServiceVersion": "1.0",         

         "X-CSRF-Token":"Fetch"                                 }                   

                         }, 

                         function (soData, response)

                        

                         {

             header_xcsrf_token = response.headers['x-csrf-token'];

                          OData.request

                          ({ 

                               requestUri:

                                "proxy/http/xxxxx.xxxxx.net:8000/sap/opu/odata/sap/ZO_DOCU_SRV/zordertypeSet", 

                                     method: "POST", 

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

         "Content-Type": "application/atom+xml",

             "DataServiceVersion": "1.0", 

         "Accept": "application/atom+xml,application/atomsvc+xml,application/xml",

         "X-CSRF-Token": header_xcsrf_token    }, 

                                     data: oData

                                        

                                  },

                                  function (soData, response)

                                    { 

                                  

                                  // document.location.reload(true);

                                                     //$("<div>Returned data " + window.JSON.stringify(oData) + "</div>").appendTo($("#MessageDiv"));

                                    //console.log(JSON.stringify(response));

                                    sap.m.MessageToast.show("success Order Number is: "+response['data']['SalesDocumentNo']);

                                    //debugger;

                                   

                             

                                    }, 

                                   

                                           function (err) 

                                           {

                                                $("<div>Returned error " + window.JSON.stringify(err.response) + "</div>").appendTo($("#MessageDiv"));

                                           }

                          );

                }, 

                function (err) 

                               {

                                    var request = err.request; // the request that was sent.

                                    var response = err.response; // the response that was received.

                                    alert("Error in Get -- Request "+request+" Response "+response);

                                    Enav = '1';

                               }

                );

       

         /*  if(Enav = '0'){

         this.nav.to("SalesDocument");

           

         }*/

          

          

           }else{

           return;

           }

          

          }

      }

    );

},