Reports.csp

To download the CSP files from this tutorial, click TutorialSamples.zip. For more information, see Code examples.

<%@ Language=JavaScript%>

<HTML>

<HEAD>

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

<link REL=STYLESHEET TYPE='text/css' HREF='tut.css'>

</HEAD>

<BODY>

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

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

<%


function RetrieveReports(ParentID ,IStore)

{

//This returns an HTML table that is populated with the report name,

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


//Precondition:

//ParentID - The ID of the parent folder containing the reports to be retrieved.

//IStore - The InfoStore object required to interface with server.



//Postcondition:

//Returns an empty string if there are no reports, null if an error occurred, and

//the string if successful.


//Notes:

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


    //The query that will select the reports.

    var Query;  

    //The result of the query.

    var Result;

    //A string to hold the HTML table.

    var HTMLTable;

    HTMLTable="";

            

    //Create a query that selects all the reports, but doesn't select the instances.

    Query = "Select SI_NAME, SI_ID, SI_DESCRIPTION, SI_UPDATE_TS From CI_INFOOBJECTS Where " +

    "SI_PROGID='CrystalEnterprise.Report' And SI_INSTANCE=0 AND SI_PARENT_FOLDER=" + ParentID;

        

        

    //Query the server.

    try {

        Result = IStore.Query(Query) ;

    }

    catch(e) {

        return null;

    }

    

  

    if (Result.Count > 0) {

        //Set up the table header.

        HTMLTable="<TABLE width = \"100%\" >" +

        "<TR><TH><B>Name</B></TH>" +

        "<TH><B>Description</B></TH>" +

        "<TH><B>Last Modified</B></TH></TR>";

                

        for (k=1;k<=Result.Count;k++)

        //Add the report name and details to the table.    

        {

            HTMLTable=HTMLTable +

                "<TR  valign=top><TD>" +

                "<A HRef='ReportDescription.csp?ReportID=" + Result.Item(k).ID +

                "&FolderID=" + ParentID + "' Target='Main'>" +

                Server.HTMLEncode(Result.Item(k).Title) + "</A></TD>" +

                "<TD>" + Server.HTMLEncode(Result.Item(k).Description) + "</TD>" +

                "<TD>" + Result.Item(k).Properties.Item("SI_UPDATE_TS") + "</TD></TR>";

        }

        HTMLTable=HTMLTable+"</TABLE>";

    }

        

    return( HTMLTable);

}


function RedirectWithFrames(URL)

{

    Response.Write ("<script language=javascript>open (\""+URL+"\",\"_top\");</script>");

}


var Result;

var ReportNames;

var ReportIDs;

var IStore;

var CurrentFolderID;

var Error;


//Retrieve the CurrentFolderID from the file's parameter list.

CurrentFolderID = Request.QueryString.Item("FolderID") ;


//Try to retrieve the InfoStore object.

IStore=RetrieveIStore();

if (IStore==null )

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

    RedirectWithFrames ("LogonForm.csp");

else

{

    var HTMLTable ;

    HTMLTable= RetrieveReports(CurrentFolderID, IStore,Error);

    if (HTMLTable!=null )

    {

        Response.Write ("<B>Report Listing</B><BR><BR>");

        if (HTMLTable != "" )

        {

            Response.Write (HTMLTable);

        } else

            Response.Write ("No reports...");

    }

    else

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

}

    




%>

</BODY>

</HTML>



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