Send TXDataWebDataSet to XData Service

I have a XData Service declared as follows:

function txxxservice.SaveData(vTableData:TJSONObject): boolean;
begin
 // work with data
end;

I am able to send one Record from a table with following code:

var
  JSVal: JSValue;
  JSObj: TJSObject;
begin
  JSVal:=tmytable.CurrentData;
  JSObj:=toObject(JSVal);
  vResponse := await(vClient.RawInvokeAsync(vEndPoint, [JSObj]));

How do I create a JsonArray and add each Record of the table? Is there any helper functions for this?

You are expecting a TJSONObject in your XData service.
But you want to send a TJSONArray to it? Is my understanding correct?

I expect a JSON object with different values like

{
"Type": "example...",
"Table1data": [ jsonarray ],
....
}

You can do something like (untested):

var
  JSObj: TJSObject;
  JSArr: TJSArray;
begin
  JSObj := TJSObject.new;
  JSArr := TJSArray,new;
  JSObj['Type'] := 'example...';
  JSObj['Table1data'] := JSArr;

  tmytable.First;
  while not tmytable.Eof do
  begin
    Rows.push(tmytable.CurrentData);
    tmytable.Next;
  end;

  vResponse := await(vClient.RawInvokeAsync(vEndPoint, [JSObj]));
1 Like

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