Adding a query function

The next step is to query the server using the Query Method that is provided by the InfoStore object. Query will examine the APS InfoStore for all the InfoObjects you are trying to find.

Result = IStore.Query(Query);

Remarks

The result, which is an InfoObjects collection, is parsed in order to retrieve the selected items. In this case, since the query specified that only folders were to be retrieved, all the InfoObjects will represent directories, or folders. The InfoObjects collection contains numerous properties of various types, some of which may be simple properties and some of which may be containers or property bags. A property bag may contain more property bags, which may contain additional property bags, and so on. For now, however, only two of these properties are of interest:

Processing the results of the query

The final step in this function is processing the results of your query using the Count and Item properties named above. If Count is greater than zero, then the folders that were retrieved will be printed. Paste the following code into your file to finish the function.

Example

var k;

//Check that there are folders to view.

if (Result.Count > 0) {

    //Retrieve the folder IDs from the query result.

    Response.Write ("<UL>")

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

    {

        Response.Write ("<LI>" + "<A HRef='Home.csp?FolderID="+Result.Item(k).ID + "' target='_top' >"+

        Server.HTMLEncode(Result.Item(k).Title) + "</A><BR>");

    }

    Response.Write ("</UL>")

} else Response.Write ("No Sub-Folders");

Remarks

The most interesting line in this slice of code is the response:

Response.Write ("<LI>" + "<A HRef='Home.csp?FolderID="+Result.Item(k).ID +

"' target='_top' >"+

Server.HTMLEncode(Result.Item(k).Title) + "</A><BR>");

The method displays a link to one of the sub-folders in the current directory. The link takes on the form

<A href='Home.csp?FolderID=AFolderID'>Folder Name</a>

The link instructs the page Home.csp to be loaded. This page hasn't been discussed yet, but it is important in that it provides the frames definition for a home page. It divides the browser window into three separate frames and loads the Folders pages into the left most frame. See Home Page.

The folder ID is given to the frames page so that it can pass it on to both the Folders.csp page and the Reports.csp page, which you will examine shortly. Consequently, both the Folders page and the Reports page are loaded with a new folder ID and display both the sub-folders and the reports for that page.

To give you a better idea of how the links work, here is the HTML code that was produced by the Folders page at the top level of the myAPS folder tree.

<a href='home.csp?FolderID=885'>-Tutorial Folder 1</a><BR>

<a href='home.csp?FolderID=886'>-Tutorial Folder 2</a><BR>

There are two top-level folders in this example. Each of them has a corresponding ID number. Assume that you click the link to Tutorial Folder 1. When this happens, its ID number (885) is be sent to the frames page, which will re-load the folders page and hand it the new ID. The folders page will then display all the sub-folders for Tutorial Folder 1.

Note that in this code segment the ID property is accessed directly without using the Properties collection. More often than not, however, the Properties property will need to be used in order to access properties in the list. This is because some common properties have been built into the SDK object model while others can only be accessed by using the InfoObject's Properties property. This will be illustrated later in Creating an "Up a Level" link.

RetrieveChildFolders now prints a list of child folders when given their parent folder's ID number. You may recall, however, that your original intention was to list all the top-level folders. How do you go about doing this? Folders on the top level have no parent, thus their SI_PARENTID is zero. When the folder page is initially loaded, you call RetrieveChildFolders like this:

RetrieveChildFolders(IStore, 0)

For a complete version of the RetrieveChildFolders function, see Folders.csp.

Go to next step:

Retrieving the parent folder



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