ReportDescription.csp

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

<%@ Language=JavaScript%>

<HTML>

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

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

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

<BODY>


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

<%

// Constants that are used in RetrieveReportInformation's return values:

var NAME=0;

var DESCRIPTION=1;


function RetrieveReportInformation(ReportID, IStore)

{

//This function retrieves the name and description of a particular report

//given its ID number.  


//Precondition:

//ReportID - The ID of the report currently being viewed.

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

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


//Postcondition:

//Returns the name and description of the report in an array and null

//if the function did not succeed.


    //The query that will select the report details.

    var Query;


    //The result of the query.

    var Result;

            

    //A query that selects report details.

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

    "SI_ID =" + ReportID;

            

        

    //Query the server.

    Result = IStore.Query(Query);

          

    if ( Result.Count > 0 ) {

        var Info = new Array(2);

        //Retrieve the name.

        Info[NAME]=Server.HTMLEncode(Result.Item(1).Title);


        //Retrieve the description.

        Info[DESCRIPTION]=Server.HTMLEncode(Result.Item(1).Description);

        return(Info);

    } else return(null);

}


function RetrieveReportInstances(ParentID, IStore,  LogonToken)

{

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

//description and the last time it was modified.


//Precondition:

//ParentID - The ID of the parent report containing the instances to be retrieved.

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

//LogonToken - The user's logon token so that a link can be provided to view

//              each instance.


//Postcondition:

//Returns an empty string if there are no instances, null if there was an error, and

//the string if successful.


//Notes:

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


    //The query that will select the instances.

    var Query;  

    //The result of the query.

    var Result

    //A string to hold the HTML table in.

    var HTMLTable;

    HTMLTable="";

            

    //Create a query that selects all the instances (SI_INSTANCE=1).

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

        "SI_INSTANCE_OBJECT = 1 AND SI_PARENTID=" + 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>Last Modified</B></TH></TR>";

                

        var oDescription;

        var k;

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

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

        //Ensure that each name is a link to the viewer.

        {

            oDescription = Result.Item(k);

            HTMLTable=HTMLTable +

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

                "<A Target='_blank' href='viewrpt.cwr?id=" + oDescription.ID +

                "&apsToken=" + Server.URLEncode(LogonToken) + "' >" +

                Server.HTMLEncode(oDescription.Title) +  "</A></TD>" +

                "<TD>" + oDescription.Properties("SI_UPDATE_TS") + "</TD></TR>";

        }

        HTMLTable=HTMLTable+"</table>";

    }

    return (HTMLTable);

}


function RedirectWithFrames(URL)

{

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

}


var IStore;

var CurrentReportID, CurrentFolderID;

var Error;


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

CurrentReportID = Request.QueryString.Item("ReportID");

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

{

    //This is the link back to the folder view listing all the reports.

    Response.Write ("<a href='Reports.csp?FolderID="+CurrentFolderID +

        "'><font size=-1>&lt&lt View Report Listing</font><P><a>");


    ReportInfo = RetrieveReportInformation (CurrentReportID, IStore);

    if (ReportInfo != null)

    {

        Response.Write ("<H1>" + ReportInfo[NAME] + "</H1>");

                

        //Draw the thumbnail in a table so that it has a border and scale

        //it to be a little smaller.

        Response.Write ("<P><TABLE Width='100%'><TR VAlign='Top'><TD>" +

            "<TABLE Border=1><TR><TD><CENTER><B>Preview</B></CENTER>" +

            "<IMG Width=159 Height=206 SRC='ThumbNail.csp?ReportID="+CurrentReportID +

            "'></TD></TR></TD></TABLE>");




    //Response.Write "<P><TABLE Width='100%'><TR VAlign='Top'><TD>" & _

    //           "<TABLE Border=1><TR><TD><CENTER><B>Preview</B></CENTER>" & _

    //           "<IMG Width=159 Height=206 " & _

    //        "SRC=""thumbnail.csp?ReportID=" & CurrentReportID &" ""></TD>" & _

    //            "</TR></TABLE></TD>"

            

            

            

        //Write the report's description.

        Response.Write ("<TD>" + ReportInfo[DESCRIPTION] + "</TD></TR></TABLE>");


        //Write out the instances associated with the report.

        Response.Write ("<BR><H1>Instances</H1>");

        var Instances;

        var LogonToken;

        //Retrieve the logon token so that the instances can be viewed in the report viewer.

        LogonToken = GetCookie("LogonToken");

        Instances = RetrieveReportInstances( CurrentReportID,IStore,LogonToken);

                        

        if (Instances!=null )

        {

            if ( Instances=="" )

                Response.Write ("<P>There are no instances of this report." +

                    " Schedule the report to create an instance of it.</P>");

            else

                Response.Write  (Instances);

        }

        else

            Response.Write ("Error: I could not retrieve the instances of this report.");


        //Write the links that enable the user to view, rename a schedule a report.


        //View

        Response.Write ("<HR><CENTER><A Target=\"_blank\" HRef=\"viewrpt.cwr?id=" +

        CurrentReportID + "&APSToken="+Server.URLEncode(LogonToken)+"\"> View Report</A> - " );

        //Rename

        Response.Write ("<A HRef='ChangeReportNameForm.csp?ReportID="+CurrentReportID +

        "&ReportName=" + Server.URLEncode(ReportInfo[NAME]) + "&FolderID="+ CurrentFolderID +

        "'>Rename Report</A>");


        //Schedule

        Response.Write (" - <A HRef='ScheduleForm.csp?ReportID="+CurrentReportID +

        "&FolderID=" + CurrentFolderID +" '>Schedule Report</A></CENTER>");

    }

    else    Response.Write ("There was an error trying to retrieve the report details.");

}



%>

</BODY>

</HTML>



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