1. #1
    Sencha User
    Join Date
    Sep 2012
    Posts
    29
    Vote Rating
    0
    cassiopeia is on a distinguished road

      0  

    Default 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?
    Attached Images

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,642
    Vote Rating
    899
    Answers
    3574
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    Moved to ST2 Q&A forum (was posted in Ext JS 4 Q&A)
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    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 in print!

    When posting code, please use BBCode's CODE tags.

  3. #3
    Ext Premium User
    Join Date
    Mar 2007
    Posts
    89
    Vote Rating
    1
    Answers
    2
    Luc is on a distinguished road

      0  

    Default


    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!

  4. #4
    Sencha User
    Join Date
    Sep 2012
    Posts
    29
    Vote Rating
    0
    cassiopeia is on a distinguished road

      0  

    Default


    thank you for your response!

    my model looks like this

    Code:
    Ext.define('LeaveRequest.model.Request', {
    
                extend : 'Ext.data.Model',
    
                config : {
    
                    fields : [
                            'AbsenceTypeCode',
                            'StartDate',
                            'EndDate',
                            'Notes',
                            'ApproverEmployeeID',
                            'AbsenceTypeName', 
                            'WorkingDaysDuration',
                            'ApproverEmployeeName',
                            'StatusName'
    
                    ]
                    
                }
            });
    and the store (simplyfied) :

    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() ;
        }
    
    });
    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.
    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.

    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'],
    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.
    all the other fields i do want to send, are those from my model.

    what do you mean with setting record.phantom to false?

  5. #5
    Ext Premium User
    Join Date
    Mar 2007
    Posts
    89
    Vote Rating
    1
    Answers
    2
    Luc is on a distinguished road

      0  

    Default


    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.

  6. #6
    Sencha User
    Join Date
    Sep 2012
    Posts
    29
    Vote Rating
    0
    cassiopeia is on a distinguished road

      0  

    Default


    hi,

    multiple create operation work now! =)

    so i've put the proxy on the model and changed the create method to the following:

    Code:
    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);
                    });
    my delete method looks like this
    Code:
    record.erase();
    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.

    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 =)

  7. #7
    Ext Premium User
    Join Date
    Mar 2007
    Posts
    89
    Vote Rating
    1
    Answers
    2
    Luc is on a distinguished road

      0  

    Default


    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:

    Code:
    proxy: {
        type: 'odata',
        ......,
        headers: {
           'If-Match': '*'
        }
    }
    Also, check if you need/have the X-CSRF-Token (depends on SAP Gateway configuration)

  8. #8
    Sencha User
    Join Date
    Sep 2012
    Posts
    29
    Vote Rating
    0
    cassiopeia is on a distinguished road

      0  

    Default


    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. #9
    Ext Premium User
    Join Date
    Mar 2007
    Posts
    89
    Vote Rating
    1
    Answers
    2
    Luc is on a distinguished road

      0  

    Default


    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.

  10. #10
    Sencha User
    Join Date
    Sep 2012
    Posts
    29
    Vote Rating
    0
    cassiopeia is on a distinguished road

      0  

    Default


    i don't think that's the problem, because otherwise it wouldn't work either when i restart the app =)

Thread Participants: 2

Tags for this Thread