Retrieving the parent folder

This section will add support for an "Up a Level" link that returns the user to a folder one level up in the tree. It is similar to the RetrieveChildFolders function except in the way it accesses the results.

Creating an "Up a Level" link

To create a link such as this, you need to know:

Once you have the ID of the current folder, you can retrieve its parent from the APS. The parent's ID will be used later to retrieve its children using the RetrieveChildFolders function.

Add the following RetrieveParentID function to Folders.csp:

RetrieveParentID function

Function RetrieveParentID(IStore, ChildID, ParentID)

'This function retrieves the ID number of a particular folders

'parent.

'

'Precondition:

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

'ChildID - The ID of the child whose parent ID is to be retrieved.

'

'Postcondition:

'ParentID - Stores the ID of the child's parent.

'

'Notes:

'ParentID will be empty if there is no parent.

'If an error occured the function returns FALSE, otherwise it returns TRUE.


    'The query that will select all the child folders.

    Dim Query            


    'The result of the query.

    Dim Result            

      

    'Create a query that selects the parent's ID for a folder.

    Query = "Select SI_PARENTID From CI_INFOOBJECTS Where SI_ID = " & _

    ChildID & " And SI_PROGID = 'CrystalEnterprise.Folder'"

          

On Error Resume Next

    'Query the server.

    Set Result = IStore.Query(Query)

    If Err.Number <> 0 Then

        'There was an error querying the server.

        RetrieveParentID=False

        Exit Function

    End If

      

    If Result.Count > 0 Then

        'Retrieve the ID from the query result.

        ParentID = Result.Item(1).ParentID

    End If

    RetrieveParentID=True

End Function

Remarks

The RetrieveParentID function is very similar to the RetrieveChildFolders function. Two lines of particular importance are different, however, and it is worth examining these in more detail.

query = "Select SI_PARENTID from CI_INFOOBJECTS where SI_ID = " & _

    ChildID & " and SI_PROGID = 'CrystalEnterprise.Folder'"

This line is the query that finds the parent ID of a specified child folder. Note that this time, the SI_PARENTID Property is used instead of the SI_PARENT_FOLDER Property. While the two have been used interchangeably here, note that they are not equivalent. The following diagram illustrates the difference between them.

In the case of this diagram, an instance is owned by a report, and the report is owned by a folder. That is, the SI_PARENTID property for the Instance refers to the Report, and the SI_PARENTID property for the report refers to the folder. The SI_PARENT_FOLDER property for both the instance and the report, however, refer to the folder, and not the report.

The second line worth noting in the example above is this one.

ParentID = Result.Item(1).ParentID

In this line, the ID of the parent folder is retrieved, but instead of accessing it directly, as was done before for SI_ID (see ), the Item's Properties value is used.

Go to next step:

Retrieving the current folder



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