Automatic Export via URL API
The URL API can give you a lot of flexibility in designing report interactions. I’ve previously talked about using it to Answer Prompts to simulate drill downs from Documents, customize the layout by Removing Sections, or providing links to Reports and Folders as a Landing Page. Today, I’ll talk about how you can use the URL API to setup export defaults for a variety of formats. You may want to do this if you have a complex Dashboard and want to provide an “Export to Excel” link for the raw data behind the scenes or individual components or link to an export from an external application.
The URL in MicroStrategy contrains all of the instructions for what the output should be. Whether that output is a folder to browse, a Report to run or an Export. To start, you’ll need to get the correct URL for your Report or Document. This is NOT the URL from your address bar! That URL almost certainly contains additional session information specific to you and will not work for other users (including future you).
To get the correct starting URL, right click on a Report or Document in Web, choose Show Link, and copy the link from the top box. (Note: This will use the internal machine name of your web server. If you use a DNS name for Extranet access, you’ll instead want to go to Properties and copy the link from the bottom of that window).
The default URL you get will look like this:
Step 1 – Event
The first thing we’ll need to edit is the event. 4001 is the event for running a report. Here are some useful ones for our purposes:
- 3067 – Report – Excel, CSV & Plain Text
- 3062 – Report – PDF
- 3069 – Document – PDF, Excel, CSV & Plain Text
This Event ID needs to replace both &evt=4001 and &src=Main.aspx.4001.
Step 2 – executionMode
Next, we need to add a parameter for the executionMode. Our options:
- 3 – PDF
- 4 – Excel
- 7 – Flash
So, to export to Excel, it would be &executionMode=4
Step 3 – Default Export Options
To configure the options for your export, simply run your Report or Document normally, export it from Web normally, and configure the export via the options. Complete the export, then save the report. The options you chose will be saved with it and used as the future defaults.
Once setup, add the parameter &showOptionsPage=false so that this page won’t display.
Note: If you want to export to Plain Text or CSV, follow the path to export to Excel (executionMode=4) and configure the file output option in your Default Export Options.
Step 4 – Clean up
You can remove the &visMode parameter and the ¤tViewMode from your URL. Those control the visualization and Grid/Graph mode respectively, and you probably won’t need those for your export. That said, you can leave them and they won’t hurt anything.
When you’re finished, if you want to have a URL that automatically returns an Excel file from a Report, you’ll end up with one like this: