Search.csp

To download the CSP files from this tutorial, click TutorialSamples_vb.zip. For more information about using the samples, see Code examples.


<HTML>

<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=charset=UTF-8">

<BODY>

<!-- #include file=RetrieveIStore.csp -->

<%



Function SearchForReport(SearchString ,IStore, Error)

'This function searches for a report that contains the

'sub string, SearchString, and returns an HTML table

'that is populated with the report name,

'report description, and the last time it was modified.

'

'Precondition:

'SearchString - The string that will help identify the report.

'IStore - The InfoStore object required to interface with the server.

'Error - A variable to hold the error if one occurs.


'

'Postcondition:

'Error - Contains the error number: 0 if successful.


'

'Notes:

'The function returns a string that is an HTML table.


    'The query that will select the reports.

    Dim Query  

    'The result of the query.

    Dim Result

    'A string to hold the HTML table.

    Dim HTMLTable

    HTMLTable=""

    Dim StrCSearch


    StrCSearch = SearchString

        

    'Create a query that selects all the reports, and the instances.

    Query = "Select SI_NAME, SI_ID, SI_DESCRIPTION, SI_UPDATE_TS, SI_PARENT_FOLDER " & _

    "From CI_INFOOBJECTS Where SI_PROGID='CrystalEnterprise.Report' And SI_NAME LIKE '%" & StrCSearch & "%'"

    

On Error Resume Next

    'Query the server.

    Set Result = IStore.Query(Query)

    If Err.Number <> 0 Then

        'There was an error querying the server.

        Error=Err.Number

        Exit function

    End If


    

    If Result.Count > 0 Then


        'Set up the table header.

        HTMLTable="<TABLE Border=0 Width = ""100%""><TR><TD><B>Name</B></TD>" & _

        "<TD><B>Description</B></TD>" & _

        "<TD><B>Last Modified</B></TD></TR>"

        

        Dim oReport

        For Each oReport in Result

        'Add the report name and details to the table.

            HTMLTable=HTMLTable & _

            "<TR  valign=top><TD>" & _

            "<A HRef='ReportDescription.csp?ReportID=" & CStr(oReport.ID) & _

            "&FolderID=" & oReport.Properties("SI_PARENT_FOLDER") & _

            "' Target='Main'>" & oReport.Title & "</A></TD>" & _

            "<TD>" & oReport.Description & "</TD>" & _

            "<TD>" & oReport.Properties("SI_UPDATE_TS") & "</TD></TR>"

            

            Next

        HTMLTable=HTMLTable&"</TABLE>"

    End If

    

    SearchForReport    =HTMLTable

    'Indicate success.

    Error=0

End Function


Dim Result

Dim IStore

Dim Error

Dim SearchString


'Retrieve the search string from the search form.

SearchString = Request.Form("SearchString")


'Try to retrieve the InfoStore object.

If RetrieveIStore(IStore)=FALSE Then

    'If it failed, redirect the user to the logon page.

    Response.Redirect "LogonForm.csp"


Else

  Dim HTMLTable

  HTMLTable = SearchForReport(SearchString, IStore,Error)

  If Error=0 Then

    Response.Write "<B>Report Listing</B><BR><BR>"

    If HTMLTable <> "" Then

        Response.Write HTMLTable

    Else

        Response.Write "No reports were found"

    End If

Else

    Response.Write "There was an error trying to retrieve the reports."

End If


End If


%>

</BODY>

</HTML>




Crystal Decisions, Inc.
http://www.crystaldecisions.com
Support services:
http://support.crystaldecisions.com