How to Launch Crystal Server Reports Via URL and Include Parameters
So You have a report in your Crystal Server that you want to share or include in another site, well, im going to teach you how to use the OpenDoc URL to run the report.
Here is how it works
Let’s say you have a report called Invoices.rpt located in the “Asset Management” Folder
The report has a main report and a sub report. The report takes 2 paramenters, PONumber for the main report, and CheckNUM for the subreport
You Only really need a few parameters, and they are:
NOTE: I’m assuming that your crystal viewer is “Single Sign On”, we don’t need to or care to pass a user name and password, if it is not, your user will get prompted for his credentials. I suggest you work on getting SSO working, as this makes the process quick and painless
How to get the Report ID
In order to get the report ID, right click the report and select properties
The ID is shown under the Report Title (this is the same as iDocID)
Now we need to get the Parameters that the report is prompting for
How to get the Report Parameters
Right Click on the Report, and Select View
It will take you to the report viewer, at which point it will prompt you for the parameters it needs
Note the names that it is prompting for. The main report is prompting for “PoNumber” While the Subreport is prompting for “CheckNUM” (and the reason that we know it is a sub-report is because it is wrapped around in parenthesis)
Now that we know what parameters we need, is time to build our URL
How To build the Report URL
All report URLS will begin with http://mycrystalserverurl/OpenDocument/opendoc/openDocument.aspx?
If we visit this url, you will see that Crystal gives an error that says
"An error has occurred:An error occured while trying to view the document “
obviously we need to let the viewer know which report to load, so that’s what the ID is for, so now if we go to http://mycrystalserverurl/OpenDocument/opendoc/openDocument.aspx?idocid=9767 (9767 being the ID we gathered before)
We now get the same parameter prompt that we had above, but the Goal here is to automatically pass the parameters to the report, so that’s where the “lsS” variable comes in to play
By adding the parameter in the form of lsSPARAMETERNAME, we now see that the report only prompts for the parameter in the sub report http://mycrystalserverurl/OpenDocument/opendoc/openDocument.aspx?idocid=9767&lsSPONumber=2150
But simply adding lsSPARAMETERNAME wont target the parameter in the sub-report. In order to do that, you need to add something to the lsS variable. It needs to be in the form of lsSPARAMETERNAME@SUBREPORTNAME. Notice the “@” symbol, it is important to include it along with the name of the sub-report, otherwise crystal won’t know where to set the variable
So now, we have our complete URL that looks like this:
Notice that the name of the sub-report in the lsS variable must match whatever the name was in the parenthesis. So now we have a url that once clicked, it will take you to the report viewer ready to view the report
But wait, what about promptOnRefresh, ah yes, well, that parameter is pretty self explanatory, but I will explain it anyway. When you created your report, you made it to prompt you for the parameters which we pre-filled with the lsSVariableName, but If your user clicks on the refresh button, they will be prompted for the parameters again. If you set promptOnRefresh to “0”, then even if the user hits the refresh button, they will not get prompted again for the parameters. The report will always continue to use the original parameters that were passed to it in the URL.
Here is a sample URL with promptOnRefresh:
That’s all, now you are a Crystal Server URL reporting expert 🙂
Comments are closed.