on 04-25-2016 9:03 AM
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", "");
});
}
Hi ....
Is i have tried all solution still error of token is coming..
how we are go through this issue ...?
Thanks in Adv.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Umesh,
Can you share the HTTP Request URI and the payload that you are using for PUT request?
Few points to consider:
Regards,
Ekansh
Hi Ekansh
var PostReq = url+"/sap/opu/odata/sap/ZPO_LGWZ_CHG_SRV/PO_HEADER_SET('1000003042');
http://user:password@00.00.000:000/sap/opu/odata/sap/ZPO_LGWZ_CHG_SRV/PO_HEADER_SET('1000003042');
these URI are you saying ...?
Regards,
Umesh
http://user:password@00.00.000:000/sap/opu/odata/sap/ZPO_LGWZ_CHG_SRV/PO_HEADER_SET('1000003042')?$expand=PO_Navigation/POCOND_NAVI
Hi Ekansh
This my UI code HTTP request body for PUT call
sap.m.MessageToast.show('header_xcsrf_token',header_xcsrf_token);
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){
console.log('Data POST Resp:l-',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", "");
}
); // oData POST Request
}
}
},
function (err) {
hdpage.setBusy(false);
itmpage.setBusy(false);
matnrpage.setBusy(false);
vendpage.setBusy(false);
sap.ui.commons.MessageBox.alert("Error Ocurred: " + ' ' + err.message, "", "Error", "");
});
}
Regards
Umesh
Hi Umesh,
I have already suggested you to check your payload that it should not contain Navigation Property.
The payload should contain only the properties which belong to POHeader entityset and there should not be any mention of navigation property which you might be using while Create (POST) call.
As per your PostData variable (details are not present in the above reply, one has to go and check the code in the question...sad), you are appending an array of LineItems Navigation Property.
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
};
}
Please remove that array, then it would trigger the UPDATE_ENTITY method. I have already mentioned the reason behind this in my previous reply.
Regards,
Ekansh
To make a successful PUT(Update) call you need to follow below steps. We will use 'Gateway Client' for testing.
1. Implement Get_Entity and Update_Entity methods.
2. Fire the Get_Entity method and fetch the XSRF token and click on 'Use as Request' button.
3. Change the values you want to update in the request body.
4. Fire the Update_Entity method.
5. The results should be updated.
BR.
Hi Umesh,
Can you please test at Gateway client first rather than jumping directly to any of the browser based client and check with an external debugger in UPDATE_ENTITY. Also post the snapshot of what error message you will get after doing this.
Thanks
Parth
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Umesh,
You see 'Method Not Allowed' error when the Service method is not implemented.
For example, When implementing POST, service method 'CREATE_ENTITY' has to be implemented and for PUT, service method UPDATE_ENTITY. So try changing your method to POST rather than PUT and see if it works.
Adding to this, generally when using POST method, we implement the 'GET_ENTITY' method (and not GET_ENTITYSET method) else it will result in some 415 error. Check that if it works that way.
Here, in my service, I've implemented GET_ENTITY and POST (CREATE_ENTITY) and working fine. For the same process, if i try PUT service, getting this error. Try changing your method to POST once.
Regards,
Santosh
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Santosh,
It is not working like u said,
See i explain my scenario i had one service which is creating PO succesfully, the method contains GET and POST. PO created successfully.
I created similar new service with different name working fine in gateway and i am using same code in .js, now in this i am just replacing PUT in place of POST. but i am getting this all error.
Exactly, you cannot just change POST to PUT. For Put, you have to implement UPDATE_ENTITY method and as Jibin said, the URL would have the key included as well.
See it this way, when creating a PO, use POST and when changing a PO, you specify the PO number as part of URL and update, the method implementation differs in gateway.
For GET ....
var serviceURI = url+"/sap/opu/odata/sap/ZPO_LGWZ_CHG_SRV/PO_HEADER_SET('"+txt_PrevPO.getValue()+"')?$expand=PO_Navigation/POCOND_NAVI";
For PUT ...
var PostReq = url+"/sap/opu/odata/sap/ZPO_LGWZ_CHG_SRV/PO_HEADER_SET('1000003042');
1000003042 this is my PO as a 'key' as u said...
I am getting user id & password here which automatically appending before IP address in URL when i check in console i think this is not the problem?
http://user:password@00.00.000:000/sap/opu/odata/sap/ZPO_LGWZ_CHG_SRV/PO_HEADER_SET('1000003042');
Hi Umesh,
Apart from the suggestions mentioned by other colleagues, please also check the UI code. As far as I understand you have copied the same JS code as was for create scenario. You need to modify the call from oModel.create to oModel.update and use method PUT as per API Doc .
BR.
i get this below error when i try to update.. first GET is succesful and then PUT shows x-scrf-Token required..
I dont understand why this happening please help me to resolve my issue.
i have shared my code in this thread above.. please have look.
this same code works when i try to do POST operation instead of PUT.
Discussion successfully moved from SAPUI5 Developer Center to SAP Gateway
as suggested.
By the way, it is better to simply Alert Moderator with Wrong Space than make the suggestion in the Discussion. This brings it to the attention of the Moderators who can then move the entire Discussion to a more appropriate community (like I just did). The member who started the Discussion does not have the same ability unless they start a new Discussion which then violates the Cross Posting part of the Rules of Engagement.
Cheers, Mike (Moderator)
SAP Technology RIG
Hi Umesh,
Seems the PO Document which you are updating does not exist? Please check that.
BR
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Ankit....
When i entering PO after clicking on edit button it fetching data from ECC but after editing for update we have save button when i am trying to click on SAVE PO Button then it raise an error.....
PUT http://.........../sap/opu/odata/sap/ZPO_LGWZ_CHG_SRV/PO_HEADER_SET/ 405 (Method Not Allowed)
Thanks in Adv...
Update an Entity
The OData services SHOULD support PATCH as the preferred means of updating an entity. But also services MAY additionally support PUT. The request below update the Emails of a person using PATCH.
PATCH serviceRoot/People('russellwhyte')
OData-Version: 4.0
Content-Type: application/json;odata.metadata=minimal
Accept: application/json
{
"@odata.type" : "Microsoft.OData.SampleService.Models.TripPin.Person",
"Emails" : ["Russell@example.com", "Russell@contoso.com", "newRussell@contoso.com"]
}
Maybe PATCH would help. As we clearly see 405 ( with PUT ) - Method Not Allowed.
i am getting response as below in browser...
<?xml version="1.0" encoding="utf-8"?><error xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"><code>005056A509B11ED199D8826D151FC0FE</code><message xml:lang="en">The specified HTTP method is not allowed for the resource identified by the Data Service Request URI</message><innererror xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"><transactionid>BEB80BE629F4F1D4BE730050569C4F03</transactionid><timestamp>20160426141119.7080000</timestamp><Error_Resolution><SAP_Transaction>Run transaction /IWFND/ERROR_LOG on SAP NW Gateway hub system and search for entries with the timestamp above for more details</SAP_Transaction><SAP_Note>See SAP Note 1797736 for error analysis (https://service.sap.com/sap/support/notes/1797736)</SAP_Note></Error_Resolution></innererror></error>
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.