Passing Search Criteria from Web Tier
I am developing a Web application where I will have reports that contain
both AutoSearchCriteria fields and standard SearchCriteria fields.
I would like to do the following :
1 - pass a URL to the Web Tier that contains QueryFields. Certain of these
QueryFields will be prefixed with a string to tell the Web Tier to pass
these fields as parameters to the Report Server.
2 - in the Report Server I would like to take these parameters and assign
them to the appropriate Search Criteria Fields before the report is run
3 - Any AutoSearchCriteria fields would be displayed as normal - allowing
the user to input values via the web interface.
I have the first part worked out, but am having issues in determining how I
can set the Search Fields (non AutoSearchFields) on the server side.
Any help would be greatly appreciated.
both AutoSearchCriteria fields and standard SearchCriteria fields.
I would like to do the following :
1 - pass a URL to the Web Tier that contains QueryFields. Certain of these
QueryFields will be prefixed with a string to tell the Web Tier to pass
these fields as parameters to the Report Server.
2 - in the Report Server I would like to take these parameters and assign
them to the appropriate Search Criteria Fields before the report is run
3 - Any AutoSearchCriteria fields would be displayed as normal - allowing
the user to input values via the web interface.
I have the first part worked out, but am having issues in determining how I
can set the Search Fields (non AutoSearchFields) on the server side.
Any help would be greatly appreciated.
This discussion has been closed.
Comments
Here is what I am doing.
1 - In the Web Tier I am setting the TrsWebRequest.ServiceParameters to all
QueryString pram that contains a prefix of 'PARAM_'. I just strip the
leading 'PARAM_' and add the key/value pair to the
TrsWebRequest.ServiceParameters.
2- At the server, I find the CriteriaField in the BeforePublishReport event
and update it appropriately (see code below)
function CriteriaIndexByName(SQL : TdaSQL; FieldName : string) : integer;
var
iIndex : integer;
begin
result := -1;
for iIndex := 0 to SQL.CriteriaCount-1 do
begin
if SQL.Criteria[iIndex].Field.FieldName = FieldName then
begin
result := iIndex;
break;
end;
end;
end;
procedure TdmAllShipments.rsReportTemplateAllShipmentsBeforePublishReport(
Sender: TObject; aEventParams: TrsBeforePublishReportEventParams);
var
lReport : TppReport;
fLocal : TppField;
iCriteriaField,
iIndex : integer;
pLocal : TppParameter;
begin
if (aEventParams.Report is TppReport) then
begin
lReport := TppReport(aEventParams.Report);
for iIndex := 0 to aEventParams.ReportParameters.Count-1 do
begin
pLocal := aEventParams.ReportParameters.ItemsByIndex[iIndex];
fLocal := lReport.DataPipeline.GetFieldForName(pLocal.name);
if fLocal <> nil then
begin
iCriteriaField :=
CriteriaIndexByName(TdaQueryDataView(fLocal.DataPipeline.DataView).SQL,pLoca
l.name);
if iCriteriaField <> -1 then
begin
TdaQueryDataView(fLocal.DataPipeline.DataView).SQL.Criteria[iCriteriaField].
value := pLocal.value;
TdaQueryDataView(fLocal.DataPipeline.DataView).SQL.Criteria[iCriteriaField].
Field.ShowAllValues := false;
end;
end;
end;
end;
end;
Everything is working great. The only outstanding issue I have now is that
if I attempt to call ValidateReportParameters in the Web Tier I get a
message about not being able to create a directory. It looks like the
directory is the cache directory. If I do not call the
ValidateReportParameters function, the report does generate correctly. The
cache directory does get created correctly.
I surmising that it has something to do with the ordering on the Web Tier
side. I call the logic in the Web Tier from the default action on the
WebModule. See code below.
function TwmodAmeriReports.ValidRequest(Request: TWebRequest) : boolean;
begin
result :=
end;
procedure TwmodAmeriReports.WebModule1WebActionItem1Action(Sender: TObject;
Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
var
lWebRequest: TrsWebRequest;
begin
if ValidRequest(Request) then
begin
{use the incoming request parameters to create a TrsWebRequest}
lWebRequest := rsWebTier1.CreateWebRequest(Request.QueryFields,
Request.Content);
try
Response.Content := ProcessReportParameterRequest(lWebRequest);
finally
lWebRequest.Free;
end;
end
else
Response.SendRedirect();
end;
procedure TwmodAmeriReports.AddParamsToSession(aWebRequest:TrsWebRequest);
var
iIndex : integer;
sServParamKey,
sQueryKey : string;
param : TppParameter;
begin
for iIndex := 0 to aWebRequest.ContentParameters.Count-1 do
begin
param := aWebRequest.ContentParameters.ItemsByIndex[iIndex];
if ((length(param.Name) > length('PARAM_')) and
(AnsiContainsText(param.name,'PARAM_'))) then
begin
sServParamKey := copy(param.name,7,length(param.name)-6);
aWebRequest.ServiceParameters[sServParamKey].Value := param.Value;
aWebRequest.ContentParameters.Remove(param.name);
end;
end;
end;
function
TwmodAmeriReports.ProcessReportParameterRequest(aWebRequest:TrsWebRequest):
String;
begin
{add custom service parameters to be sent to the report server}
AddParamsToSession(aWebRequest);
{request a refresh, to avoid to getting a cached report}
aWebRequest.ContentParameters['Refresh'].AsBoolean := True;
try
if rsWebTier1.ValidateReportParameters(aWebRequest) then
Result := rsWebTier1.ProcessWebRequest(aWebRequest);
except on E: Exception do
Result := rsWebTier1.HandleException(aWebRequest, E);
end;
end;
Once again, any help would be greatly appreciated.