An external application can make use of Sage CRM reports. It is not appropriate to invoke HTML reports from a 3rd party or external application as these are designed to interact with the Sage CRM interface.  You only need think about the auto hyperlinking feature which allows drill down into Sage CRM records from an HTML report to realise that the flat nature of PDF reports would be more useful.

But how could we generate a PDF report from with a windows or a web application?

Below you can see that I have done exactly this

I used a number of different facts.

  • Reports can be called via URLs.
  • The URL passes the ID of the report to be generated and the required context to restrict the data.
  • The URLs can include a flag to control that a PDF is generated.
  • All Sage CRM URLs that include the eWare.dll in the path require that a Session ID (SID is used).

To call a report like one above the URL would need to look like


This idea has been used before in the article "Adding a Report Button to an Existing System Screen, e.g. OpportunitiesList".

When building a button in an ASP page we can use code that looks like

[code language="javascript"]
//intReportAction is either 1410 to display the report options or 1411 to directly run the report
//var intReportAction = 1410;
var intReportAction = 1411;
//Allowed values for strDestination are "Screen", "Adobe", "CSV", "Excel"
var strDestination = "Adobe";
var strSummaryReportButton = CRM.Button("Print to Excel", "executesummaryreport.gif", CRM.URL(intReportAction)+"&Key41=31&FlgNewWindow=True&Destination="+strDestination+"&PageSize=210x297&Orientation=Landscape", "", "", "EWARE_HELP")

We can see that the parameters of "Destination" and "Action" are important to control that the report is immediately run to generate the PDF file.

We can use the fact that the Session ID is used by the SOAP Web Services as the authentication token.  If we log-on to Sage CRM via SOAP then we can use the same SID to build the URL to the report.

I have show the example code below

[code language="csharp"]
        private void FetchReport_Click(object sender, EventArgs e)
            string strUserName = textBox1.Text;
            string strPassword = textBox2.Text;
            logonresult CRMLogon = CRMService.logon(strUserName, strPassword);
            CRMService.SessionHeaderValue = new SessionHeader();
            CRMService.SessionHeaderValue.sessionId = CRMLogon.sessionid;
            //build URL for ASP page using Sage CRM objects
            string strURL = "http://localhost/CRMReporting/eware.dll/Do?Act=1411&Mode=1&CLk=T&Key0=41&Key4=1&Key41=37&Destination=Adobe&PageSize=210x297&Orientation=Landscape&SID=";
            strURL += CRMLogon.sessionid;
            //Browse to the Sage CRM page
            webBrowser1.Visible = true;

The hardest part then becomes how we might find out what the ID of the report (Key41) should be used.  But that is a subject for another article.