Adding the RetrieveIStore function

At this point, you should have a general idea about how to check for and retrieve the InfoStore object. Create a new CSP page and save it as RetrieveIStore.csp. Add the following function.

RetrieveIStore function

To download the CSP files from this tutorial, click TutorialSamples.zip. For more information, see Code examples.

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


<%


function RetrieveIStore()

{

//Precondition: None


//Postcondition:

//Returns the InfoStore object that allows you to query the server.


//The function returns null if it does not succeed.



    var LogonToken;

    var SessionManager;

    var Sess;

    //Try to retrieve the cookie.

    LogonToken = GetCookie("LogonToken")

    

    //Check to see if a logon token was really retrieved.

    if( LogonToken != "" )

    {

            

        //Check to see if the InfoStore already exists.

        if( typeof(Session.Value("IStore").Item) != "object" )

        {

                                            

            //Create a session manager.

            SessionManager = Server.CreateObject("CrystalEnterprise.SessionMgr");

                        

            //Logon using the token. This may fail if the token is no longer valid.

            Sess = SessionManager.LogonWithToken(LogonToken);

                        

            //Create the InfoStore object.

            IStore = Sess.Service("", "InfoStore");


            //Save the InfoStore in the session.

            SetSession("IStore",IStore);

            return (IStore);

        }

        else

        {

            //The InfoStore already exists so simply retrieve it from

            //the session.

            IStore = GetSession("IStore")

            return(IStore);

        }

    }

    else return(null);

}

%>

Remarks

Since you must have the InfoStore object to query the APS, you will want to include the RetrieveIStore function on any page that retrieves folders, reports, and/or report instances. You can do this by using a Server Side Include (SSI) statement such as the following:

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

Note:    Server Side Includes are supported by ASP/CSP. They are essentially the same as normal include files found in C and C++ programming environments. For more information, please refer to an ASP programmer's guide.

Go to next step:

Lesson 2a: Navigating through folders



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