Hi, when using Dataset.GetPendingUpdates to extract the JSON, how can I format the TDateFields date to match my requirements? Currently, it is always exported in the format 'yyyy-mm-ddT00:00:00.000Z', but I only need the 'yyyy-mm-dd' part. The field is connected to a TWebDBDateTimePicker of kind dtkDate.
There is a DefaultFormat to set? Or any hint for solve?
Thanks
The default format is the ISO 8601 format which is the JSON standard format.
In a JSON dataset, the ftDate, ftTime and ftDateTime fields are respectively represented by TJSONDateField, TJSONTimeField and TJSONDateTimeField.
These classes have properties TJSONDateField.DateFormat, TJSONTImeField.TimeFormat and TJSONDateTimeField.DateTimeFormat with which the default format can be overridden.
Hi Bruno,
Thanks.
Can you write a quick code example with uses for setting generally those in WebCore?
I need the correct format that match deserialize that Json in Xdata service, with use TxdataJsonServerDeserializer (and relative TxdataJsonServerSerialize in another service).
Thanks a lot!
@Monterisi_Stefano can you please elaborate a little bit more about what you are trying to accomplish, and when, exactly? It's not clear to me the relation between TWebDBDataTimePicker and TXDataJsonServerDeserializer. There is a very long path between one and another.
Of course :-)
I use TwebClientDataset.Get PendingUpdates to extract the Json of the changes made in the dataset, to be sent via an XDATA service that takes care of doing the CRUD on the server with Aurelius classes.
This service is generic, so I pass a Json array that contains both the name of the class (Invoice for example, row by row) and the content of the modified or inserted records.
In this way, on the server side, I receive a json containing the crud of several tables in a single call.
A function creates the necessary Aurelius objects and fills them through
TxdataJsonServerDeserializer, before performing the validation and saving (TInvoice.Save, TInvoice.update, TInvoice.Remove).
In short A generic service that allows the crud for several tables in a single transaction and a single call, and that works well.
The problem is that in the Json created by Tweb ClientDataset.Get PendingUpdates, fields of type Tdate are exported in the format 'yyyy-mm-ddT00:00:00.000Z'
and not 'yyyy-mm-dd'.
This format in the Tdate field is NOT accepted, server side, by TxdataJsonServerDeserializer that raises an exception.
Example of server side:
function ApplyUpdateGen(AApplyUPD: Tlist): String;
var
tmpApplyUPD: TApplyUPD;
Deserializer: TXdataJsonServerDeserializer;
tmpValue: string;
I: integer;
tmptable: string;
tmpoperaz: integer;
tmpObject: Tobject;
tmpManager: TObjectManager;
transaction: IDBTransaction;
ValidationResult: IManagerValidationResult;
Error: IValidationError;
begin
result:='KO';
tmpManager:= TXDataOperationContext.Current.GetManager;
Deserializer := TXdataJsonServerDeserializer.Create(TXDataAureliusModel.default,nil);
transaction:=tmpmanager.Connection.BeginTransaction;
try
for I := 0 to AApplyUPD.Count -1 do
begin
tmpApplyUPD:= AApplyUPD[i];
tmptable:= tmpApplyUPD.D1;
tmpOperaz:= tmpApplyUPD.D2;
tmpValue:=tmpApplyUPD.D3.ToString;
tmpObject:=DeserializzaObject(tmpManager, Deserializer,tmptable,tmpValue);
if tmpObject <> nil then
begin
tmpManager.Validate(tmpObject);
if tmpOperaz=1 then
begin
tmpManager.Save(tmpObject);
result:='OK INS';
end;
if tmpOperaz=2 then
begin
tmpManager.Update(tmpObject);
result:='OK UPD';
end;
if tmpOperaz=3 then
begin
tmpManager.Update(tmpObject);
tmpManager.Remove(tmpObject);
result:='OK DEL';
end;
end;
end;
//
if tmpmanager.HasChanges then
tmpmanager.Flush; // save updates to DB
//
transaction.Commit;
//
except
.....
......
Now it's clear
Try to use this approach:
and here is a more detailed explanation about the options:
Hi,
Ok, I will try tomorrow.
But the TWebClientDataset.GetPendingUpdates must convert TDateFields date into 'yyyy-mm-dd' format, not 'yyyy-mm-ddT00:00:00.000Z'.The bug remain in Tms WebCore, a correction is necessary.
Thanks a lot.