Home Server
New Blog Posts: Merging Reports - Part 1 and Part 2

Auto search and hidden session params

edited July 2005 in Server
Hi,
I have implemented the below exactly (from an old thread "Search not
appearing")
as I have the same problem.

-----------------------------------------------------------------------------------------
1. Implement the custom login form as shown in the custom parameters demo.
This will allow the user to specify the session parameters used for all of
the reports he/she runs during a session.

2. For the reports, define AutoSearch parameters for the additional info to
be entered by the user from the standard autosearch dialog.

3. Allow the AutoSearch feature to work automatically

4. The remaining piece is to apply the session parameter info to the report
query. This can be done on the server side by implementing the
ReportVolume.BeforePublishReport event. The aEventParams object passed to
the event-handler provides access to the report instance and to the
SessionParameters. You can extract the TdaSQL object associated with the
report query and apply the SessionParameter values by adding search criteria
to the TdaSQL object. Here is an example of extracting and modifying the
TdaSQL object...

www.digital-metaphors.com/tips/ExtractSQLObject.zip
--
Nard Moseley
Digital Metaphors Corporation
www.digital-metaphors.com
-------------------------------------------------------------------------------------------

I wish to pass an id from a session variable with out the user knowing and
also prompt
for auto search fields. I followed these instructions exactly. However, if
I have auto search I get an AV. Then if I take away the auto search the
report works no problems with my adjusted sql. If I comment out my code and
leave the auto search it also works. My guess is that it is trying to add
the SQL from the auto search to my Where clause used for my session variable
and messing up the SQL. Any one try this or have a solution.. here is some
of my code in case I am missing something. I am using rb server 7.03.

procedure TDatamodule1.rsReportExplorerVolume1BeforePublishReport(
Sender: TObject; aEventParams: TrsBeforePublishReportEventParams);
var
lReport: TppReport;
lempID: string;
begin
//Change the sql object

{add the session parameters to the report}
if (aEventParams.Report is TppReport) then
begin
lReport := TppReport(aEventParams.Report);
lempID := trim(aEventParams.SessionParameters['HR3EmpID'].AsString);
lempID := '1';
if lempID <> '' then
setSearchEmpID(lReport,strToInt(lempID));
end;

end;


procedure TDatamodule1.setSearchEmpID(aReport:
TppCustomReport;empDetails_id: integer);
var
lSelectedList: TList;
lSQL: TdaSQL;
lFields: TStringList;
lCriteria: TdaCriteria;
liIndex: Integer;
begin

{get SQL object}
GetSQLObject(aReport, lSQL);
lSQL.MagicSQLText.Text;

{if criteria have not been created, then add them}
lSQL.ClearCriteria;

{get all available criteria fields}
lFields := TStringList.Create;

lSQL.AvailableCriteriaList(lFields);

{set string list entries to field names}
for liIndex := 0 to lFields.Count - 1 do
lFields[liIndex] := TdaField(lFields.Objects[liIndex]).FieldName;

{create emp no criteria}
liIndex := lFields.IndexOf('Employee_details_id');

if (liIndex <> -1) then
begin
lCriteria := lSQL.SelectCriteria(liIndex);
lCriteria.Operator := dacoEqual;
end;

lFields.Free;
{set emp no. search value}
lSQL.Criteria[0].Value := intToStr(empDetails_id);
end;


Thanks in advance
Dean Watkins

Comments

  • edited July 2005

    1. Try testing that code in a non-server environment.

    2. ReportBuilder 9 includes a new TdaSQLBuilder class that makes it much
    easier to modify the TdaSQL object. And it can be done from RAP code or
    Delphi code.

    Here is a simple example taken from the help...


    lSQLBuilder := TdaSQLBuilder.Create(Report.DataPipeline);

    lSQLBuilder.Clear;

    lSQLBuilder.SelectTables.Add('Customer');

    lSQLBuilder.SelectFields.AddAllFields;

    lSQLBuilder.SearchCriteria.AddAutoSearch('Customer', 'Company', 'Like',
    'S');

    lSQLBuilder.ApplyUpdates;

    lSQLBuilder.Free;







    --
    Nard Moseley
    Digital Metaphors Corporation
    http://www.digital-metaphors.com


    Best regards,

    Nard Moseley
    Digital Metaphors
    www.digital-metaphors.com
  • edited July 2005
    No. I don't want to buy report builder 9 yet.

    How do I save a session value for a sessionID in the web tier. Then
    retrieve that value for the appropriate session in the server.
    I have everything else working bar this.

    I have an action saveEmployeeID in the web tier

    aWebRequest.SessionParameters['HR3EmpID'].Value :=
    aWebRequest.ContentParameters['HR3EmpID'].Value;

    What do I need to do next to make this value stick for this session..
    Next I have:

    rsWebTier1.ProcessWebRequest(aWebRequest);
    This creates a new session and id. I think this may be the wrong way to do
    it. The function returns a string saying there is nothing to handle the web
    request but still creates a new session and id.

    In the server I have

    procedure TDatamodule1.rsReportExplorerVolume1BeforePublishReport(
    Sender: TObject; aEventParams: TrsBeforePublishReportEventParams);
    var
    lReport: TppReport;
    lempID: string;
    lempID2: string;
    begin
    //Change the sql object

    {add the session parameters to the report}
    if (aEventParams.Report is TppReport) then
    begin
    lReport := TppReport(aEventParams.Report);
    lempID := trim(aEventParams.SessionParameters['HR3EmpID'].AsString);

    This is right I think. I just need to know what to do at the web tier. to
    start a new session properly and store a value for that new session.


    Thanks
    Dean

  • edited July 2005

    Check out the custom parameters demo for the WebTier. (see article below).

    Check out the RBServer.hlp for TrsWebTier methods, GetSessionParameters and
    ValidateSessionParameters. Once you add the session parameters to a
    WebRequest object it will autmaticaly save/restore from the web cache.


    -------------------------------------------------------
    Tech Tips: RB Server and Custom Parameters
    -------------------------------------------------------

    The RBServer Custom Parameter demos show how to define custom session and
    report level parameters that can be used to implement security and other
    types of custom processing.

    The are three projects that work together. Each project includes a
    ReadMe.doc and commented code.

    1. RBServer\Demos\Servers\Custom Parameters
    2. RBServer\Demos\WebTier\Custom Parameters
    3. RBServer\Demos\Clients\Custom Parameters


    The demos include examples of how to...

    1. Define Custom Session parameters.

    A custom login form is displayed. Based upon the login, the catalog of
    reports available to the user is filtered.

    2. Define Custom Report parameters

    A custom parameter form is displayed. The parameters are used by the report.

    3. Custom AutoSearch form

    A custom autosearch form is displayed. The parameter values are used by the
    autosearch criteria.





    --
    Nard Moseley
    Digital Metaphors Corporation
    http://www.digital-metaphors.com


    Best regards,

    Nard Moseley
    Digital Metaphors
    www.digital-metaphors.com
This discussion has been closed.