Skip to Content
0
Former Member
Apr 25, 2016 at 08:03 AM

Error while doing the PUT operation

3666 Views

Hi all...

Here I am trying to change purchase order then i am getting error after clicking SAVE PO button ...........


I am getting Error PUT http://......sap/opu/odata/sap/ZPO_LGWZ_CHG_SRV/PO_HEADER_SET/ 405 (Method Not Allowed).

i tried to update one of the parameters in the available oData service for my work,


Kindly help me in this and guide me so that I can update the contents in the back end.

specially look the code those i have marked in bold char PUT method...

Here is my code:

Please help me in this...........




var btnPrevPO = new sap.ui.commons.Button('btnPrevPO',{

text : "Edit PO",

style: sap.ui.commons.ButtonStyle.Emph,

press : function(){PreviousPo();}

});

var btnSavePO = new sap.ui.commons.Button('btnSavePO',{

text : "Save PO",

style: sap.ui.commons.ButtonStyle.Emph,

press : function(){PostDoc2();}

});

//------------------------------------------------------------------------

function PostDoc2(){

hdpage.setBusy(true);

itmpage.setBusy(true);

matnrpage.setBusy(true);

vendpage.setBusy(true);

var serviceURI = url+"/sap/opu/odata/sap/ZPO_LGWZ_CHG_SRV/PO_HEADER_SET('"+txt_PrevPO.getValue()+"')?$expand=PO_Navigation/POCOND_NAVI";

OData.request({ requestUri: serviceURI,

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

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

"DataServiceVersion": "2.0",

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

method : "GET",

user: "**********",

password: "************" ,

recognizeDates: true,

},

function (data, response){

stat = 0;

check_fields ();

if (stat == 1) {

hdpage.setBusy(false);

itmpage.setBusy(false);

matnrpage.setBusy(false);

vendpage.setBusy(false);

} else {

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

var PostReq = url+"/sap/opu/odata/sap/ZPO_LGWZ_CHG_SRV/PO_HEADER_SET/";

var PostData = new sap.ui.model.json.JSONModel();

var LineItmArr = [] , POCOND_NAVI = [], results = [];

var LinesLength = oModel.oData.modelData.length;

var PricLength = aCondData2.length;

for (i = 0; i < LinesLength; i++){

results = [];

for (j = 0; j < aCondData2.length; j++){

var innerdata = aCondData2[j];

for (k = 0; k < innerdata.length ; k++){

if (oModel.oData.modelData[i]['LineItem'] == innerdata[k]['LineItem']) {

if (innerdata[k]['condtype'] !== '' && innerdata[k]['condval'] !== '') {

results.push({

ChangeId : '',

CondPUnt : '1',

CondStNo : '001',

CondType: innerdata[k]['condtype'],

CondValue: innerdata[k]['condval'],

ConditionNo : '',

Currency: currency.getValue(),

Exppurchaseorder : '',

ItmNumber : innerdata[k]['LineItem'],

PoItem : innerdata[k]['LineItem']

});

}

else{

results.push({

ChangeId : '',

CondPUnt : "0",

CondStNo : '',

CondType: innerdata[k]['condtype'],

CondValue: "0.000000000",

ConditionNo : '',

Currency: currency.getValue(),

Exppurchaseorder : '',

ItmNumber : innerdata[k]['LineItem'],

PoItem : innerdata[k]['LineItem']

});

}

}

}

}

checkMandatory();

if (stat == 1) {

hdpage.setBusy(false);

itmpage.setBusy(false);

matnrpage.setBusy(false);

vendpage.setBusy(false);

} else {

var delvformat = '';

if (oModel.oData.modelData[i]['delvdate'] !== '') {

jQuery.sap.require("sap.ui.core.format.DateFormat");

var oDateFormat = sap.ui.core.format.DateFormat.getDateTimeInstance({pattern: "yyyy/MM/dd"});

var dateTemp = oModel.oData.modelData[i]['delvdate'];

delvformat = oDateFormat.format(new Date(dateTemp));

}

oModel.oData.modelData[i]['AccAss'] = oModel.oData.modelData[i]['AccAss'].replace(/\s/g,''); // Remove spaces

oModel.oData.modelData[i]['matgroup'] = oModel.oData.modelData[i]['matgroup'].replace(/\s/g,''); // Remove spaces

oModel.oData.modelData[i]['gl'] =

oModel.oData.modelData[i]['material'] = oModel.oData.modelData[i]['material'].replace(/\s/g,''); // Remove Space

oModel.oData.modelData[i]['netprice'] = oModel.oData.modelData[i]['netprice'].replace(/\s/g,''); // Remove Space

.

.

.

.

.

oModel.oData.modelData[i]['copaSalDoc'].replace(/\s/g,''); // Remove Space

DelDatcatExt : '',

DeleteInd : '',

DeliveryDate : delvformat,

Exppurchaseorder : '',

GlAccount : oModel.oData.modelData[i]['gl'],

.

.

.

Quantity : oModel.oData.modelData[i]['POQty'],

SalesDoc : oModel.oData.modelData[i]['copaSalDoc'],

ShortText : oModel.oData.modelData[i]['shorttext'],

});

PostData = {

"CompCode" : ComCode.getValue(), "CompCodeX" : "",

"CreatedBy" : createdby.getValue(), "CreatedByX" : "",

"Currency" : currency.getValue() , "CurrencyX" : "",

"DeleteInd" : "", "DeleteIndX" : "",

.

.

.

.

.

"Vendor" : txt_vendor.getValue() , "VendorX" : "" ,

"hTextNote" : hTextNote.getValue(),

"CondNbtval" : CONDNBT.getValue(),

"PO_Navigation":

LineItmArr

};

}

}

if (stat == 1) {

} else {

var chk_lngth, chk_cond ;

chk_lngth = '';

chk_lngth = PostData.PO_Navigation.length;

for (k = 0; k < PostData.PO_Navigation.length ; k++){

chk_cond = '';

chk_cond = PostData.PO_Navigation[k].POCOND_NAVI.length;

if (chk_cond == 0) {

PostData.PO_Navigation[k].POCOND_NAVI.push({

ChangeId : '',

CondPUnt : "0",

CondStNo : '',

CondType: '',

CondValue: "0.000000000",

ConditionNo : '',

Currency: currency.getValue(),

Exppurchaseorder : '',

ItmNumber : '',

PoItem : ''

});

}

}

OData.request({

requestUri: PostReq,

method: "PUT",

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

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

"DataServiceVersion": "2.0",

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

"X-CSRF-Token": header_xcsrf_token

},

user: "**********",

password: "***********" ,

data : PostData,

// data : temp,

},

function (data, response){

hdpage.setBusy(false);

itmpage.setBusy(false);

matnrpage.setBusy(false);

vendpage.setBusy(false);

if(data['Msg'] == 'E'){

tptext.setText(data['Return_Msg']);

tptext.setDesign("Bold");

tp1.addStyleClass("colorRedText");

tp1.setTitle("Error in Posting Document ");

tp1.open(sap.ui.core.Popup.Dock.BeginCenter, sap.ui.core.Popup.Dock.RightTop);

}else{

tptext.setText(data['Return_Msg']);

tptext.setDesign("Bold");

tp1.setTitle("PO Doc # : " + data['Exppurchaseorder']);

tp1.open(sap.ui.core.Popup.Dock.BeginCenter, sap.ui.core.Popup.Dock.RightTop);

tp1.addStyleClass(".colorRedText");

clearLineitm();

clearPricing();

}

},

function (err) {

hdpage.setBusy(false);

itmpage.setBusy(false);

matnrpage.setBusy(false);

vendpage.setBusy(false);

sap.ui.commons.MessageBox.alert("Error Ocurred: " + ' ' + err.message, "", "Error", "");

}

);

}

}

},

function (err) {

hdpage.setBusy(false);

itmpage.setBusy(false);

matnrpage.setBusy(false);

vendpage.setBusy(false);

sap.ui.commons.MessageBox.alert("Error Ocurred: " + ' ' + err.message, "", "Error", "");

});

}