AddReport.csp


<%@ Language=JavaScript %>

<% // Adds a report to a folder. %>

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

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

<HTML>

<HEAD>

</HEAD>

<BODY>


<%



function AddReport(FolderID, ReportName, InfoStore)

{

// Adds a report to a particular folder.

//

// PARAMETERS

//

// FolderID [IN]

//     The ID of the folder which will contain the report.

// ReportName [IN]

//     The full path and file name of the report.

// InfoStore

//     The InfoStore used to communicate with the server.


// RETURNS

// Returns the ID of the newly added report.

// If the function fails, it returns zero.


    // The Report plugin.

    var ReportPlugin;


    // The PluginManager.

    var pmgr;


    // Step 1.

    // Since reports are implemented using a plugin

    // you will need the PluginManager to retrieve the Report plugin.

    pmgr = InfoStore.PluginManager;

    

    // Step 2.

    // Retrieve the Report plugin by passing the plugin's ProgID

    // to the PluginInfo property of the PluginManager.

    ReportPlugin = pmgr.PluginInfo("CrystalEnterprise.Report");



    var NewCollection;

    var NewReport;


    // Step 3.

    // Create a new, empty InfoObject collection.    

     NewCollection = InfoStore.NewInfoObjectCollection();


    // Step 4.

    // Give the Report plugin object to the Add method.  This

    // creates a new InfoObject based on the plugin type.

    // In this case, since the plugin is the Report plugin,

    // the object created is a report object.  The new report object

    // is added to the empty collection.

     NewReport = NewCollection.Add(ReportPlugin);


    // Step 5.

    // Add the report data to the Files Collection. Do this using

    // the collection's Add method. The report data may be specified

    // in the form of a path and file name, or in a binary stream format

    // that contains the report data. If a path is specified, it must be

    // a valid path on the WCS.

    NewReport.Files.Add (ReportName);


    // Step 6.

    // The next line indicates where in the folder tree the

    // report is to be added.  It does this by setting the

    // parent ID property or, in other words, by telling the report

    // which folder it is to be placed in. If the parent ID property is

    // zero, the report will not be committed properly.  If the parent ID

    // is not a folder, the report will not be committed properly.

    NewReport.Properties.Add ("SI_PARENTID",FolderID);



    // Step 7.

    // Retrieve the report's interface and try to enable

    // its thumbnail image.

    var ireport;

    ireport = NewReport.PluginInterface;

    ireport.EnableThumbnail = true;

        

    // Step 8.

    // Use the InfoStore to commit the new collection with the new report

    // to the APS database.      

    try {

        InfoStore.Commit (NewCollection);

    }

    catch(e) {

        // There was an error so return 0.

        return  (0);

    }

  

    return (NewReport.Id);

    

}


function GetFolderID(FolderName, IStore)

{

// Returns the ID of a folder given the folder name.

// It will search for all folders with this name anywhere

// in the tree and return the first one it finds.

//

// RETURNS

// The folder ID or 0 if the function failed.

    var Result;

     Result = IStore.Query("SELECT SI_ID FROM CI_INFOOBJECTS WHERE SI_PROGID='CrystalEnterprise.Folder' And SI_NAME = '" + FolderName + "'");

    if (Result.Count > 0 )

        // There is a folder with that name.

        // There may be more than one, but for this example just take the first.

        return (Result.Item(1).ID);

    else

        return 0;

    

}


function Main()

{

// The main subroutine in the file.  It logs on to the APS, retrieves the

// path and filename of the report as well as the folder in which the report

// will be placed and then adds it.


    // The InfoStore object used to query the APS.

    var IStore;

    // The name of the folder that will store the report.

    var FolderName;

    // The path and file name of the report.

    var ReportName;

        

    IStore = RetrieveIStore();

    if (IStore == null )

        Response.Redirect("Start.csp");

    else

    {

        

        FolderName = Request.Form.Item ("FolderName");

        ReportName = Request.Form.Item ("ReportName");

        var NewReportID;

        var FolderID;

        Response.Write("Getting folder ID of folder " + FolderName + " and adding the report, " + ReportName);

        FolderID = GetFolderID(FolderName, IStore);

        if (FolderID != 0 )

        {

            // Add the report.

            NewReportID = AddReport(FolderID, ReportName, IStore);

            if (NewReportID != 0)

                Response.Write ("<BR>Report added. <BR>");

             else

                Response.Write ("<BR>Couldn't add report.");

            

        } else Response.Write ("<BR>The folder to which the report was to be added cannot be found.");

    }

}


Main(); // Start the script.

%>

</BODY>

</HTML>





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