Lesson 3c: Renaming reports

While Crystal Enterprise is not designed to manipulate reports themselves or compile web pages that perform complicated administrative tasks, it does allow some basic write functionality. Simple things such as scheduling information and report and folder properties may be written to the server.

In this section, you'll provide a link that enables the user to change the name of a report. This will be accomplished by two pages: the first will gather the required information from the user, and the second will change the name of the report and write the new one back to the server.

Gathering report information from the user

The first page is a form that gathers information from the user. It takes three parameters:

Renaming the report

Once the new name has been entered by the user, the data is transferred to the page named RenameReport.csp along with the report's ID and the CurrentFolderID. The name is changed and the user redirected to the page detailing the current report.

Renaming a report requires you to do the following:

  1. Select the name of the report using a query (for example, Select SI_NAME from CI_INFOOBJECTS where SI_ID=ID).
  2. Change the name of the report in the result of the query.
  3. Write the result back to the APS using the member function Commit provided by InfoStore.
ChangeReportName function


Function ChangeReportName(ReportID ,IStore, Error, NewName)

'This function changes the name of a report given its

'ID and new name.

'

'Precondition:

'ReportID - The ID of the report.

'NewName - The new name for the report.

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

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


'

'Postcondition:

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

    

    'The query that will select the name of the report.

    Dim Query  

    

    'The result of the query.

    Dim Result

        

    'Retrieve the current name of the report.

    Query = "Select Top 1* From CI_INFOOBJECTS Where " & _

    "SI_ID=" & CStr(ReportID)

    

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

        'Change the name.

        result.Item(1).Title =NewName

                

        'Write the result back to the APS.

        Call IStore.Commit (Result)


        'Check if the write was successful.

        If Err.Number <> 0 then

            Error = Err.Number

            Exit Function

        End If

    End If

    

    'Indicate success.

    Error=0

End Function


The function reads the name of the report (SI_NAME), changes the name, and commits the changes to the server. If this is done successfully, then the user is redirected to the Report Details Page; otherwise an error message is displayed.

End of lesson

You have reached the end of the lesson. What follows are two complete CSP pages: the first page, ChangeReportNameForm.csp, is a form that allows the user to modify the name of a report, and the second page, RenameReport.csp, writes the new name to the server.

Go to next step:

Lesson 3d: Scheduling reports



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