SmartClient Version: SNAPSHOT_v9.1d_2013-09-08/LGPL Development Only (built 2013-09-08)
Firefox 14
I need to have my datatime sent to my rest server in in the .toSerializeableDate format. ie instead of this
2013-10-02T21:02:00 I need 2013-10-02 21:02:00
I have subclassed the RestDatasource to so I can set default properties and add a couple of things to transform request.
I have this for my add request
But if I use this it messes up Oldvalues
Here is an example of the post reqest data with working formatRequest with format date field stuff commented out
Initial Add new record request
All is well
Then if I try to update this record after I get the new record Id and Version from the server, this is what I expect and is working all of the Oldvalues are persisted and only changed fields are sent. The version for the update I am getting from oldValues, I will post the full transformRequest at end.
Now if I do the same add/ then update same record with the format date stuff in the add request here is the data when I try to send an update request
So you can see the oldValues is wrong as well as the data
So not sure what is going on but ultimately I just need to format the datetime json sent to the server in a format my server understands.
Here is the full sublcassed RestDataSource
Thanks,
Dan
Firefox 14
I need to have my datatime sent to my rest server in in the .toSerializeableDate format. ie instead of this
2013-10-02T21:02:00 I need 2013-10-02 21:02:00
I have subclassed the RestDatasource to so I can set default properties and add a couple of things to transform request.
I have this for my add request
Code:
if (dsRequest.operationType == "add") { // fixDates(dsRequest.data) var values = dsRequest.data // debugger; for (var field in values) { if (isc.isA.Date(values[field])) { values[field] = values[field].toSerializeableDate(); } } // debugger; }
Here is an example of the post reqest data with working formatRequest with format date field stuff commented out
Initial Add new record request
Code:
{ "dataSource":"Contact", "operationType":"add", "componentId":"contactsForm", "data":{ "date":"2013-10-03", "firstName":"aa" }, "oldValues":{ } }
Then if I try to update this record after I get the new record Id and Version from the server, this is what I expect and is working all of the Oldvalues are persisted and only changed fields are sent. The version for the update I am getting from oldValues, I will post the full transformRequest at end.
Code:
{ "dataSource":"Contact", "operationType":"update", "componentId":"contactsForm", "data":{ "firstName":"aabbb", "@rid":"#9:83", "@version":1 }, "oldValues":{ "date":"2013-10-02", "firstName":"aa", "@rid":"#9:83", "@version":1 } }
Code:
{ "dataSource":"Contact", "operationType":"update", "componentId":"contactsForm", "data":{ "firstName":"aaabbb", "@rid":"#9:82", "@version":0 }, "oldValues":{ "date":"2013-10-03" } }
So not sure what is going on but ultimately I just need to format the datetime json sent to the server in a format my server understands.
Here is the full sublcassed RestDataSource
Code:
isc.defineClass("oRestDataSource", RestDataSource); isc.oRestDataSource.addProperties({ dataFormat: "json", jsonSuffix: "", jsonPrefix: "", sparseUpdates: true, prettyPrint: true, dropExtraFields: true, fetchDataURL: "http://localhost:2480/scRequest/RestTester", addDataURL: "http://localhost:2480/scRequest/RestTester", updateDataURL: "http://localhost:2480/scRequest/RestTester", removeDataURL: "http://localhost:2480/scRequest/RestTester", operationBindings: [ {operationType: "fetch", dataProtocol: "postMessage", requestProperties: {httpMethod: "POST", httpHeaders: {"Authorization": "Basic YWRtaW46YWRtaW4="}}}, {operationType: "add", dataProtocol: "postMessage", requestProperties: {httpMethod: "POST", httpHeaders: {"Authorization": "Basic YWRtaW46YWRtaW4="}}}, {operationType: "remove", dataProtocol: "postMessage", requestProperties: {httpMethod: "POST", httpHeaders: {"Authorization": "Basic YWRtaW46YWRtaW4="}}}, {operationType: "update", dataProtocol: "postMessage", requestProperties: {httpMethod: "POST", httpHeaders: {"Authorization": "Basic YWRtaW46YWRtaW4="}}} ], transformRequest: function (dsRequest) { //debugger; if (dsRequest.operationType == "update") { debugger; var versionFld = dsRequest.oldValues["@version"] || 0; dsRequest.data["@version"] = versionFld; // fixDates(dsRequest.data) var values = dsRequest.data // debugger; for (var field in values) { if (isc.isA.Date(values[field])) { values[field] = values[field].toSerializeableDate(); } } debugger; } if (dsRequest.operationType == "add") { // fixDates(dsRequest.data) var values = dsRequest.data // debugger; for (var field in values) { if (isc.isA.Date(values[field])) { values[field] = values[field].toSerializeableDate(); } } debugger; } return this.Super("transformRequest", arguments); } })
Thanks,
Dan
Comment