-
6 Nov 2012 9:12 AM #1
Unanswered: SAP bug create
Unanswered: SAP bug create
Hi,
i'm using the oData connector to create/delete/read/update SAP data.
when i execute 1 CRUD, everything works fine.
but after a first create, when i execute a second one, the first create gets executed again.
so the first create is no problem, but every CRUD operation that follows will cause the previous operation to be executed again.
in the image, you can see the logs of the gateway access.
is this a bug?
-
8 Nov 2012 7:50 AM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,684
- Vote Rating
- 435
- Answers
- 3111
Moved to ST2 Q&A forum (was posted in Ext JS 4 Q&A)
Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.
-
8 Nov 2012 2:00 PM #3
Are you saving an individual model or are you syncing a store in which you have added new models?
If you are syncing a store, a repeat create suggest that the operation didn't set record.phantom to false. It may be an issue with processing ids returned from the server.
If you provide us with some more code, maybe we can help you further.
Hope this helps!
-
8 Nov 2012 11:25 PM #4
thank you for your response!
my model looks like this
and the store (simplyfied) :Code:Ext.define('LeaveRequest.model.Request', { extend : 'Ext.data.Model', config : { fields : [ 'AbsenceTypeCode', 'StartDate', 'EndDate', 'Notes', 'ApproverEmployeeID', 'AbsenceTypeName', 'WorkingDaysDuration', 'ApproverEmployeeName', 'StatusName' ] } });
this part is hard to explain, but the service in SAP to perform a create expects all the fields to have a value. so when trying to post a new request, it expected also an ID for that request.Code:Ext.define('LeaveRequest.store.MyRequestsStore', { extend : 'Ext.data.Store', requires : ['LeaveRequest.proxy.oData', 'Ext.data.reader.Xml', 'Ext.data.writer.Xml', ...], config : { storeId : 'myrequestsstore', model : 'LeaveRequest.model.Request', sorters : { property : 'StartDate', direction : 'ASC' }, proxy : { type : 'odata', enablePagingParams : true, withCredentials : true, username : LeaveRequest.util.Config.getUsername(), password : LeaveRequest.util.Config.getPassword(), // 10.0.80.83 // http://ws8flex83.sap.flexso.com:8000 url : '/sap/opu/odata/GBHCM/LEAVEREQUEST/LeaveRequestCollection' } }, loadEntries : function() { this.load(); }, createEntry : function(record) { this.add(record); this.sync(); }, deleteEntry : function(record) { this.remove(record); this.sync() ; } });
i put a 'post exit' on de create method from the service, that allows fields to be null.
this works for a create, but only when you put 'm:null=true' between the tags of the xml feed you send.
herefor, i needed to adapt the oData file.
so all the fields i never want to add to a POST, i put out of the for loop. as you can see, these have the 'null' between the tags.Code:xmlDocumentTpl : [ '<?xml version="1.0" encoding="UTF-8"?>\n', '<atom:entry xmlns:atom="http://www.w3.org/2005/Atom" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xml:base="http://ws8flex83.sap.flexso.com:8000/sap/opu/odata/GBHCM/LEAVEREQUEST/">\n', '<atom:category term="LEAVEREQUEST.LeaveRequest" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"/>\n', '<atom:content type="application/xml">\n', '<m:properties>\n', '<d:RequestID> </d:RequestID>\n', '<d:ChangeStateID>0000000001</d:ChangeStateID>\n', '<d:LeaveKey>test</d:LeaveKey>\n', '<d:ActionCode m:null="true"/>\n', '<d:ProcessCheckOnlyInd m:null="true"/>\n', '<d:StatusCode m:null="true"/>\n', '<d:StartTime m:null="true"/>\n', '<d:EndTime m:null="true"/>\n', '<d:WorkingHoursDuration m:null="true"/>\n', '<d:ActionDeleteInd m:null="true"/>\n', '<d:ActionModifyInd m:null="true"/>\n', '<d:LastChangeDate m:null="true"/>\n', '<d:LastChangeTime m:null="true"/>\n', '<d:LastChangeEmployeeName m:null="true"/>\n', '<d:SequenceID m:null="true"/>\n', '<d:LeaveRequestType m:null="true"/>\n', '<d:FirstSubmissionDate m:null="true"/>\n', '<d:FirstSubmissionTime m:null="true"/>\n', '<d:EmployeeID> </d:EmployeeID>\n', '<tpl for=".">\n ', '<d:{key}>{value}</d:{key}></tpl>\n', '</m:properties>\n', ' </atom:content>\n', '</atom:entry>\n'],
all the other fields i do want to send, are those from my model.
what do you mean with setting record.phantom to false?
-
9 Nov 2012 3:16 AM #5
Hi,
Thanks for the additional clarification and code. How do you actually send the Request to the server?
Adding a new model to the store and using store.sync()?
And does the double create happen once you added a new model to the store and sync() again?
If so, this may indicated that the record you saved isn't flagged as such. And therefore it will be saved to server again on each store.sync() call.
Sencha Touch maintains a 'phantom' property on models to indicate that a new model is not yet persisted to the server.
-
9 Nov 2012 3:47 AM #6
hi,
multiple create operation work now! =)
so i've put the proxy on the model and changed the create method to the following:
my delete method looks like thisCode:var entry = Ext.create('LeaveRequest.model.Request', { AbsenceTypeCode : record.AbsenceTypeCode, StartDate : start, EndDate : end, ApproverEmployeeID : record.ApproverEmployeeID, Notes : record.Notes, WorkingDaysDuration : 0, ApproverEmployeeName : approvername, AbsenceTypeName : absencename, StatusName : 'Sent' }); entry.save(function(records, operation) { console.log(records); console.log(operation); });
so, with this code, i can create and delete as much as i want, except that i can't delete a request that i've created in the same browser session.Code:record.erase();
this gives me an error 405 - method not allowed
i didn't find the problem to this yet.
but thank you so much for your help. your reply to my post from a month ago helped me realize that i should change the place of the proxy =)
-
9 Nov 2012 4:18 AM #7
Hi,
Great you got it working!
Getting the 405 error intermittently is weird. It suggest the DELETE verb is not allowed, but you would expect to get this error consistently. Have you checked if you get any response from SAP Gateway which could point to the issue? Use Chrome Developer Tools, Network tab to view the server response.
It may be the case that a DELETE request requires a 'If-Match: *' http request header, but on SAP gateway demo system this leads to a 428, not a 405. But you can try it out:
Also, check if you need/have the X-CSRF-Token (depends on SAP Gateway configuration)Code:proxy: { type: 'odata', ......, headers: { 'If-Match': '*' } }
-
9 Nov 2012 4:25 AM #8
hi,
the respond from SAP gateway is:
"The specified HTTP method is not allowed for the resource identified by the Data Service Request URI"
the error logs in SAP gateway don't give any information, but that isn't a surprise
-
9 Nov 2012 4:40 AM #9
OK, I recognize that error message.
I got it once when I tried to use DELETE on a collection, for example:
DELETE /sap/opu/odata/GBHCM/LEAVEREQUEST/LeaveRequestCollection
instead of deleting an entity
DELETE /sap/opu/odata/GBHCM/LEAVEREQUEST/LeaveRequestCollection('....')
Maybe you can check if that is the case.
-
9 Nov 2012 5:01 AM #10
i don't think that's the problem, because otherwise it wouldn't work either when i restart the app =)


Reply With Quote