How to pass an object which have a TDateTime property to XData server method by RawInvoke call in TMS Web bootstrap project?


I am getting invalid json value error for TDatetime property when I pass an object which have a TDateTime property, to XData server method in TMS Web bootstrap project by by using xDataWebclient.RowInvoke method.

So how to pass an object which have a TDateTime property to XData server method by RawInvoke call.

I have declared a class as follow which I am trying to use in both XData server side and WebClient side to data exchange.

  TCalls = class(Tobject)
    custno: integer;
    calldate: TDateTime;
    notes: string;
    callno: Integer;
    status: string;
    ispending: string;
    endtime: TDateTime;
    allday: string;

I have following XData server methods to get and update Calls data

[HttpGet, Route('')]
function GetCalls(incustno: integer; inmonth: integer; inyear: integer): TList<TCalls>;
[HttpPut, Route('{callno}')]
procedure UpdateCall(callno: Integer; ACall: TCalls);

The GetCalls method returns data in following format which seems correct.

    "value": [
            "$id": 1,
            "custno": 1,
            "calldate": "2023-06-07T12:23:42",
            "notes": "these are the notes",
            "callno": 796,
            "status": "O",
            "ispending": "Y",
            "endtime": "2023-06-07",
            "allday": "Y"

I used following code from webclient to call the get Calls API.
XDataWebConnection1.XDataWebClient1.RawInvoke('IcallService.GetCalls', [inUserId, inMonth, inYear], @LoadCallsData_Success);

But when I call the PUT API method UpdateCall to Update a Call's details, I get bad request error. Here I pass callno and an object of TCalls class to the RowInvoke method as follow.

icallno: integer;
objCall: TCalls; 
XDataWebConnection1.XDataWebClient1.RawInvoke('IcallService.UpdateCall', [icallno, objCall], @UpdateCalls_Success);

Then I get invalid json for calldate field. And when I checked the browser developer tools console tab during webbrowser debug, it shows 400-Bad request error.

PUT http://localhost:2001/api/v1/calls/799 400 (Bad Request)

When, I checked the Network tab Payload tab, then it shows following json payload which is having incorrect value for calldate field which is a TDateTime type and same issue for endtime as well

	"notes":"Note 5",

So, how to solved the above datetime issue for json while passing an object to xData server method by using xdatawebclient RawInvoke call.

While getting data from xData server as object then the datetime is fine but while sending data to xdata server as an object then the datetime is not correct? Am I missing any setting or any property to properly serialize and de-serialize datetime values?

Please help. on how to pass an object which have TDateTime feild to xData server method by using xdatwebclient RawInvoke method.


Date time values must be strings with the date formatted as ISO 8601. It's up to you to format the date like that. In other words make sure the property is a string and the date has the format "YYYY-MM-DDTHH:NN:SS".

As a helper, you can use method TBclUtils.DateTimeToISO function available in unit Bcl.Utils.

Thank you, Wagner.

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.