How to add a report to Crystal Enterprise

This section describes how to add a report to Crystal Enterprise. The example that is included consists of two CSP files. The first file(GetReportDetails.csp) prompts the user for the path and filename of the report to be added. The second file (AddReport.csp) adds the report to the File Repository Server in the specified folder.

This section only demonstrates how to add a report that is already on the web server. For details on how to transfer a file from a client machine to the web server using a browser, see your web server documentation.

Note:    As an alternative to using CSP files to add a report, you may also use the Report Publishing Wizard.

The following parts in this section explain how to add a report in general, demonstrates this procedure using code, and finally provides a working example.

Adding a report

The following procedure assumes you have already logged onto the APS and have a current session (see Authenticating and logging on the user for information on creating a session):

To add a report
  1. Retrieve the PluginManager Object.

    The PluginManager allows you to retrieve the Report plugin, which is needed to create a report object.

  2. Retrieve the Report plugin by passing the plugin's ProgID to the PluginInfo property of the PluginManager.
  3. Create an empty InfoObjects Collection using the NewInfoObjectCollection Method in the InfoStore Object.
  4. Call the Add Method using the newly created InfoObjects Collection and the Report plugin.

    The InfoObjects Add method creates a new InfoObject based on the type of plugin you give it. In this case, it creates a new Report object and adds it to the collection. It is important to note that a report object is a type of InfoObject.

  5. Using the newly created Report object, 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 filename, or in a binary stream format that contains the report data. If a path is specified it must be a path on the web server. In the case where the Web Component Server (WCS) is not running on the same machine as the web server, this path points to a location on the WCS. You do not, however, have to be concerned with transferring the file from the web server to the WCS. This is handled for you by Crystal Enterprise. For information on transferring the file from a browser to the web server, refer to your web server documentation.

  6. Specify the folder into which the report will be placed.

    The folder into which the report is to be placed is set using the report's parent ID. If the ID is zero or the ID does not belong to a folder, the report will not be added; otherwise it is placed in the folder specified by the SI_PARENTID Property.

  7. As an optional step you can enable the report's thumbnail image using the EnableThumbnail Property.
  8. Commit the new collection to the APS using the InfoStore's Commit Method.

    This adds the report to the File Repository Server and updates the APS InfoStore.

These steps are illustrated in the following function:

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 filename 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.

    Dim ReportPlugin


    ' The PluginManager.

    Dim pmgr


    ' Step 1.

    ' Since reports are implemented using a plugin

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

    set pmgr = InfoStore.PluginManager

    

    ' Step 2.

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

    ' to the PluginInfo property of the PluginManager.

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



    Dim NewCollection

    Dim NewReport


    ' Step 3.

    ' Create a new, empty InfoObject collection.    

     set 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.

     set 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 filename, 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.


    call 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.

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



    ' Step 7.

    ' Retrieve the report's interface and try to enable

    ' its thumbnail image.

    Dim ireport



    set ireport = NewReport.PluginInterface


    ireport.EnableThumbnail = true

        

    ' Step 8.

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

    ' to the APS database.      

   ' On Error Resume Next


       call InfoStore.Commit (NewCollection)

    If Err.Number > 0 then

    ' There was an error so return 0.

    AddReport = 0

    else  

       AddReport = NewReport.Id

    end if

    

end function



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