Filling in parameters of a Schema DataTable on the server before sending data to client?


Each of my database tables has an organisation_id field. Now I need to merge two organisations data into a single database but keep them separate for each user (multi-tenancy).

I am saving the users own organisation_id in the Session as the user logs in.

Is there a central place in the DataAbstract Service, Schema or DataStreamer where I can catch requests to open any datatable and where I can set the “organisation_id” parameter (checking if it exists first)?



You can use the DataService.OnBeforeGetDatasetData event:

procedure TDataService.DataAbstractServiceBeforeGetDatasetData(aSender: TObject; const aDataset: IDADataset;
  const aIncludeSchema: Boolean; const aMaxRecords: Integer);
  lParam: TDAParam;
  lParam := aDataset.Params.FindParam('id');
  if Assigned(lParam) then lParam.Value := Session.Values['organisation_id'];
1 Like

That’s great - thanks. That will save a load of coding.