<%@language="vbscript"%>
<%
' First, get the APS name and report ID from the form variables
' sent from the html page via the POST method.
'removed default settings
'apsname=request.form("APS")
'ReportObjectID=request.form("roID")
apsname="ServerName"
ReportObjectID=request.querystring("ID")
' Start a new session with the CE SDK so we can logon or logoff to the APS
on error resume next
set oSessionMgr = Server.CreateObject("CrystalEnterprise.SessionMgr")
if err.number < 0 then
' Lots of error checking is always a good idea
' In this sample we'll just response.write errors to the browser,
' but your application can do something slicker.
response.write "Error " & err.number & ": [" & Err.Description & "] creating CE SessionManager session.<br>"
response.end
end if
on error resume next
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'set the infor for the viewer and account
set oEnterpriseSession = oSessionMgr.Logon("userName","Password",apsname,"secEnterprise")
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
if err.number < 0 then
response.write "Error " & err.number & ": [" & Err.Description & "] on logon to APS [" & apsname & "].<br>"
response.write "Can't logon.<br>"
response.end
end if
' Get a handle to the logon token manager so we can get a token to use for calls
on error resume next
Set oLogonTokenMgr=oEnterpriseSession.LogonTokenMgr
if err.number < 0 then
response.write "Error " & err.number & ": [" & Err.Description & "] Getting tokenmgr handle.<br>"
response.end
end if
' Get the actual logon token - this can be saved/restored using response.cookies
' so you can share it amongst CSP files.
on error resume next
apstoken = oLogonTokenMgr.CreateLogonToken(apsname,"1","1000")
if err.number < 0 then
response.write "Error " & err.number & ": [" & Err.Description & "] getting aps token.<br>"
response.end
end if
'response.write apstoken
' Write the apstoken to a cookie - this can be used by other CSP files
response.cookies("apstoken")=cstr(apstoken)
' Get a handle to an Info Store object so we can query the APS database
on error resume next
Set oIStore = oEnterpriseSession.Service("", "InfoStore")
if err.number < 0 then
response.write "Error " & err.number & ": [" & Err.Description & "] getting InfoStore handle.<br>"
' now logoff
oLogonTokenMgr.ReleaseToken apstoken
response.end
end if
' Get a handle to a collection of report objects with the specified ID
' (there should be exactly one report in the collection.)
on error resume next
Set cReports = oIStore.Query("Select SI_LAST_SUCCESSFUL_INSTANCE_ID, SI_ID From CI_INFOOBJECTS Where SI_ID=" & cstr(ReportObjectID))
if err.number < 0 then
response.write "Error " & err.number & ": [" & Err.Description & "] getting InfoStore query.<br>"
oEnterpriseSession.ReleaseToken apstoken
response.end
end if
' There should be exactly one report with this ID. If none, then there's no report
' to view, if more than one, there's an error in the database (duplicates.)
if cReports.Count <> 1 then
response.write "Error: " & cstr(cReports.count) & " objects found with ID " & cstr(ReportObjectID) & ".<br>"
oEnterpriseSession.ReleaseToken apstoken
response.end
end if
'Response.Write(cReports.Item(1).Properties("SI_ID") & "<BR>")
' OK now we have the report object and all we have to do is get the latest instance
' Fortunately, there's a property built-in for this!
' It's SI_LAST_SUCCESSFUL_INSTANCE_ID
' Now we are ready to view the report instance.
' This line will bring up the default ActiveX viewer
'This line checks to see if there is a Last Successful ID
'If there is, we will go to it, otherwise we will go to an On Demand page that allows you to post the parameters
if cReports.Item(1).Properties("SI_LAST_SUCCESSFUL_INSTANCE_ID") Is Nothing Then
response.redirect("/businessobjects/enterprise/admin/en/viewrpt.cwr?id=" & ReportObjectID & "&apstoken=" & cstr(apstoken) & "&init=actX:connect")
else
response.redirect("/businessobjects/enterprise/admin/en/viewrpt.cwr?id=" & cReports.Item(1).Properties("SI_LAST_SUCCESSFUL_INSTANCE_ID")& "&apstoken=" & cstr(apstoken) & "&init=actX:connect")
end if
' But we will take a few extra steps to ensure our logon token is released sooner
' By default logon tokens are timed-out after 20 minutes.
' For this we will use files ActiveXViewer.csp and Cleanup.csp.
riID = cReports.Item(1).Properties("SI_LAST_SUCCESSFUL_INSTANCE_ID")
%>