XDataWebDataset not editable after SetJsonData

Is there any reason why can't I save changes in my XDataWebDataset, which I load with data using SetJSonData method. Records are coming from XDataServer and show up properly in the grid but when i modify a field and switch to the next record my change just disappears. So even before applyupdates.
I created my fields manually in the dataset. Dataset has an ETYTYSETNAME set to a table i am selecting the records from.

Thank you.

If you have set EntitySetName and calling ApplyUpdates, why are you using SetJsonData instead of relying on the dataset to retrieve data?

In any case, we would need a project reproducing the problem to have a better idea about what's going on.

I need to be able to run my one queries in some cases and rely on the dataset when it comes to applying updates. So i created a service function in my xdata module and passing the sql as a string parameter and returning the result in TStream.
I will create a small project to share.
But I can tell know that the data for some reason is coming inside 'Original' segment so i needed to created all my fields as Original."FIELDNAME". Can that be the reason? Maybe it thinks that the field is not from the main entity assigned to xdatawebdataset and cancels changes? Same thing if I am not mistaken happens to any field from EXPANDED entity when I need to use the entity_name.field_name, which I can understand.

Hard to tell, a minimal project reproducing the problem will help indeed.

Is there a way to get the JSON data without 'Original' segment? (I am using FireDAC) . Maybe i just can remove it before loading data?

What do you mean exactly by "'Original' segment"?

This is how the rows are coming in the json response

.
.
.
{"RowID":1,"Original":
{"AbteilungsID":20,
"Abteilung":"Anwendung & Entwicklung",
"Test":"0"}
},

{"RowID":2,"Original":
{"AbteilungsID":30,
"Abteilung":"Technische Büro",
"Test":"0"}
.
.
.

This is not standard XData JSON. I believe you are serializing (generating the JSON) yourself. It's up to you to generate the JSON the way you want.

I am just saving the FireDAC query result in the stream and returning to client. I apologize for using this example. I just wanted to show the word ‘Original’ which comes the same way in my Json data. I took it from another post. I have no access to my project right now.
But I am getting the same ‘Original’ word in front of the data and need to name the fields in the dataset with ‘Original’ prefix. Original.Myfieldname.Otherwise dataset is empty after load.

Yes, that's how you should use the field names if your JSON comes with a subject named Original. Use it that way, or change your JSON to put the properties of Original directly in the root JSON object.

But how will it match the fields to apply updates. The data is coming to the client in that fields fine.
Then I cannot post the changes ( same as for any field named entityname.fieldname) but even if i could how would it understand that 'Original.' should not be taken into account when applying updates?

The dataset will always take the whole object and send it back to be updated.
If you don't want to do that, you must simply not use ApplyUpdates, but perform the changes yourself manually, using the TWebHttpRequest component.

Thank you.
In VCL appliactions there could be the object name which is different from the column name ( for example when the column was selected with alias <select column_name as my_name from ... >) and the original name (tablename.columnname) which it was using when creating an UPDATE statement. The XDATAWEBDataset also has the 'ORIGIN' property for the field. I was thinking that is the one which will be used for updates.

Understood. No, it's different it's the object itself that is used to update, the dataset is just a visual layer, a binding between the underlying object and the visual controls.

Thank you. I understand now about ApplyUpdates.
But still what about posting the data. Can I at least post the changes made in the fields with 'Original.' prefix? Changes just go away after posting.

You will have to do it completely manually, indeed.

I see. Thank you very much for your help with this.

1 Like