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

      0  

    Default Unanswered: How to post a new record with REST

    Unanswered: How to post a new record with REST


    Hi,
    I need to create new records in the SAP database.
    Reading is no problem, but I don't know which code i need to perform a POST operation.

    I work with MVC.
    My store is currently :

    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',
    
                    proxy : {
    
                        headers : 'X-CSRF-Token : ... ; '
                                + 'Content-Type : application/atom+xml ; '
                                + 'X-Requested-With : XMLHttpRequest',
    
                        type : 'odata',
    
                        enablePagingParams : true,
                        withCredentials : true,
                        username : LeaveRequest.util.Config.getUsername(),
                        password : LeaveRequest.util.Config.getPassword(),
    
                        url : ' ... ',
                        reader : {
                            type : 'xml',
                            record : 'properties'
                        }
                    }
                },
                loadAll : function() {
    
                    var proxy = this.getProxy();
                    proxy.setExtraParams('');
                    this.load();
    
                },
    
                 createEntry : function ( ... ) { ... }
    
            });
    I would like to make a new function 'createEntry' which receives the necessary parameters.
    But what do I have to write in this method?

    Thank you

  2. #2
    Sencha User crysfel's Avatar
    Join Date
    Feb 2008
    Location
    New York, USA
    Posts
    218
    Answers
    7
    Vote Rating
    8
    crysfel will become famous soon enough

      0  

    Default


    You need to add a writer to your store, this way every time you add/update/remove a record, the store will synchronize your store with your server.

    Regards

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

      0  

    Default


    So, in the proxy:

    Code:
    writer:
                        {
                            type:'xml',
                            method:'POST'
                        }
    Does it need something else?
    And how do I specify in my createEntry method that I want to post the model?

    Code:
    createEntry : function(employeeID, absenceTypeCode, startDate,
                        endDate) {
    
                    model = Ext.create('LeaveRequest.model.Request', {
    
                                'EmployeeID' : employeeID,
                                'AbsenceTypeCode' : absenceTypeCode,
                                'StartDate' : startDate,
                                'EndDate' : endDate
                            });
    
                }
    Thank you for your reply =)

  4. #4
    Ext JS Premium Member
    Join Date
    Jan 2008
    Location
    Germany, Berlin
    Posts
    135
    Answers
    21
    Vote Rating
    11
    fschaeffer will become famous soon enough

      0  

    Default


    If you're defining your proxy on the model (and not on the store) you could simply do a model.save() which would POST your model to the defined URL ...

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

      0  

    Default


    Hi,

    I assume you are using the SAP OData connector (oData.js file). It already defines appropriate reader and writer configs, so you don't need to configure them again. Like the comment from fshaeffer says, add the proxy to the LeaveRequest.model.Request instead of the store and you can then model.save()

    Hope this helps.

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

      0  

    Default


    every documentation i read on sencha, says that it's best to put the proxy inside the store.
    i will try it on the model and it maybe helps for my problem on
    http://www.sencha.com/forum/showthre...576#post909576
    which you also responded.
    thank you for your help, i hope it works =)

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

      0  

    Default


    Hi,

    Yes, you can have proxies on either the store or the model. I prefer them on the models, for reasons described in:
    ST Documentation: proxy guide

    Also the "SAP ODAta connector readme.pdf" recommends proxies on the models:
    A Sencha Touch proxy connects models and stores with servers that house the
    data used by your app. Proxies are configured with parameters to complete that
    connection, such as the server URL, data format (for example XML or JSON),
    and authentication needed to make requests on the server. (Note: the current
    implementation of the SAP oData Connector supports only XML.) Proxies can be
    defined on either stores or models, but the recommended place is the model.
    When testing connectivity to backend servers, I always start out with simple model read, create, update, delete operations and then move on to stores.

Thread Participants: 3

Tags for this Thread