on 06-04-2014 2:02 PM
Hi All,
I have created a OData Service in SAP ECC system in format
http://hostname:portno/sap/opu/odata/sap/Z_PORDER_SRV/PurchaseOrderHeaderCollection
I am trying to create a record from front end using JQuery. I am able to retrieve all the records, but creation of records using Method "POST" fails.
For creating records, using the method "GET", i fetch the token "X-CSRF-Token" and then pass the token to the "POST" method.
I am getting an Exception "No Handler for Data" error is coming. I am accessing the OData Service using the datajs framework.
(datajs-1.1.1.min.js).
Please help me in resolving this issue.
Thanks,
Divya
Did you set all of the headers correctly? Please post your code.
Regards,
Jamie
SAP - Customer Experience Group
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for the reply Jamie.
Code:
OData.request({
"http://host:port/sap/opu/odata/sap/Z_PORDER_SRV/PurchaseOrderHeaderCollection",
method : "GET",
user: Customer_Username,
password: Customer_Password,
headers :
{
"X-Requested-With" : "XMLHttpRequest",
"Content-Type" : "application/XML",
"DataServiceVersion" : "2.0",
"X-CSRF-Token" : "Fetch"
}
},
function(data, response)
{
var header_xcsrf_token = response.headers['x-csrf-token'];
OData.request(
{
requestUri : "http://host:portno/sap/opu/odata/sap/Z_PORDER_SRV/PurchaseOrderHeaderCollection",
method : "POST",
user: Customer_Username,
password: Customer_Password,
headers :
{
"X-Requested-With" : "XMLHttpRequest",
"Content-Type" : "application/XML",
"DataServiceVersion" : "2.0",
"X-CSRF-Token" : header_xcsrf_token
},
data:
{
PONumber:"4500000091",
CompanyCode:"TVSC",
PurchaseDocCategory:"F",
PurchaseDocType:"NB",
PurchaseDocStatus:"9",
CreatedBy: "",
VendorAccountNumber:"V1",
PurchaseOrganization:"PO01",
PurchaseOrgGroup:"101",
TotalValueAtRelase:"0.00",
POItem: "00010",
Material:"",
MaterialNumber: "000000000000000011",
Plant: "PL01",
MaterialGroup: "01",
TargetQuantity: "0.000",
Quantity: "5.000",
Unit: "ST",
OrderPriceUnit:"ST",
NetPrice: "10.0000",
PriceUnit:1,
GrossValue:"0.0000",
NetValue:"0.0000",
NetWeight:"0.000",
WeightUnit:"",
MaterialType:"",
PurchaseOrderHeaderPONumber:"",
PurchaseOrderHeaderPONumber1:""
}
},
function(data,response)
{
alert('Success. Created New Record');
},
function(err1)
{
alert('Error in Create Record...'+err1.message);
}
);
},
function(err)
{
alert('error....'+err.message);
}
);
Output
I get an error message "Error in Create Record. "No Handler for Data".
I tried entering the header details alone and also by entering the line items. Still the same error is thrown.
Please Help.
Thanks,
Divya
Hi Jamie,
The issue still persists. Using Rest client we checked, records are getting created. But I think, the way data is passed using jquery is wrong.
Can you please let know how to pass data in JSON format using jquery?
Should i pass the XML Structure as a String.
data: {
"__metadata": {
"id": "http://host:port/sap/opu/odata/sap/Z_PORDER_SRV/PurchaseOrderHeaderCollection('4500000001')",
"uri": "http://host:port/sap/opu/odata/sap/Z_PORDER_SRV/PurchaseOrderHeaderCollection('4500000001')",
"type": "Z_PORDER_SRV.PurchaseOrderHeader",
"properties": {
"PurchaseOrderItem": {
"associationuri": "http://host:port/sap/opu/odata/sap/Z_PORDER_SRV/PurchaseOrderHeaderCollection('4500000001')/$links/P..."
}
}
},
"PONumber": "4500000001",
"CompanyCode": "TVSC",
"PurchaseDocCategory": "F",
"PurchaseDocType": "NB",
"PurchaseDocStatus": "9",
"CreatedBy": "",
"VendorAccountNumber": "V1",
"PurchaseOrganization": "PO01",
"PurchaseOrgGroup": "101",
"TotalValueAtRelase": "0.00",
"PurchaseOrderItem": [{
"__metadata": {
"uri": "http://host:port/sap/opu/odata/sap/Z_PORDER_SRV/PurchaseOrderItemCollection(PONumber='4500000001',PO...')",
"type": "Z_PORDER_SRV.PurchaseOrderItem",
"properties": {
"PurchaseOrderHeader": {
"associationuri": "http://host:port/sap/opu/odata/sap/Z_PORDER_SRV/PurchaseOrderItemCollection(PONumber='4500000001',PO..."
}
}
},
"PONumber": "4500000001",
"POItem": "00010",
"Material": "",
"MaterialNumber": "000000000000000011",
"Plant": "PL01",
"MaterialGroup": "01",
"TargetQuantity": "0.000",
"Quantity": "5.000",
"Unit": "ST",
"OrderPriceUnit": "ST",
"NetPrice": "10.0000",
"PriceUnit": "1",
"GrossValue": "0.0000",
"NetValue": "0.0000",
"NetWeight": "0.000",
"WeightUnit": "",
"MaterialType": "",
"PurchaseOrderHeaderPONumber": "",
"PurchaseOrderHeaderPONumber1": "",
"PurchaseOrderHeader": {
"__deferred": {
}
}
}]
};
Thanks,
Divya
You do not need all those URLs in the request body. It has to be as simple as below.
data: {
"PONumber": "4500000001",
"CompanyCode": "TVSC",
"PurchaseDocCategory": "F",
"PurchaseDocType": "NB",
"PurchaseDocStatus": "9",
"CreatedBy": "",
"VendorAccountNumber": "V1",
"PurchaseOrganization": "PO01",
"PurchaseOrgGroup": "101",
"TotalValueAtRelase": "0.00",
"PurchaseOrderItem": [{
"PONumber": "4500000001",
"POItem": "00010",
"Material": "",
"MaterialNumber": "000000000000000011",
"Plant": "PL01",
"MaterialGroup": "01",
"TargetQuantity": "0.000",
"Quantity": "5.000",
"Unit": "ST",
"OrderPriceUnit": "ST",
"NetPrice": "10.0000",
"PriceUnit": "1",
"GrossValue": "0.0000",
"NetValue": "0.0000",
"NetWeight": "0.000",
"WeightUnit": "",
"MaterialType": "",
]}
}
Hi Krishna,
I tried using the same format. But still getting "No handler for data" error. I tried with content type as "application/json" and application/XML.
data:
{
"PONumber":"4500000091",
"CompanyCode":"TVSC",
"PurchaseDocCategory":"F",
"PurchaseDocType":"NB",
"PurchaseDocStatus":"9",
"CreatedBy": "",
"VendorAccountNumber":"V1",
"PurchaseOrganization":"PO01",
"PurchaseOrgGroup":"101",
"TotalValueAtRelase":"0.00",
"PurchaseOrderItem":[{
"PONumber":"4500000091",
"POItem": "00010",
"Material":"",
"MaterialNumber": "000000000000000011",
"Plant": "PL01",
"MaterialGroup": "01",
"TargetQuantity": "0.000",
"Quantity": "5.000",
"Unit": "ST",
"OrderPriceUnit":"ST",
"NetPrice": "10.0000",
"PriceUnit":"1",
"GrossValue":"0.0000",
"NetValue":"0.0000",
"NetWeight":"0.000",
"WeightUnit":"",
"MaterialType":"",
"PurchaseOrderHeaderPONumber":"",
"PurchaseOrderHeaderPONumber1":"",
}]
}
Please help in resolving this issue. It is working fine in REST Client.
Thanks,
Divya
User | Count |
---|---|
81 | |
9 | |
9 | |
7 | |
7 | |
6 | |
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.