Showing posts with label crystal reports. Show all posts
Showing posts with label crystal reports. Show all posts

20 October 2010

Simulate Report Alerts in Crystal Reports 2008 Server

Working with Crystal Reports can be tricky.  Anyone who publishes the reports on a BOE Server or Crystal Reports 2008 server has to relearn some of the aspects of the reports to create similar functionality to the desktop application.

Recently I was asked to implement an alerting scheme in a crystal report that was published to the server.  Since online reports do not support alerts the same way desktop reports do, this is a tricky problem.

The way we decided to do it was to put the alert in the report header.  We then tested for the condition that would trigger an alert.  If the condition was triggered, we made the report header visible.  Otherwise, we hid the report header.

This is accomplished with three formulas:
  • The first formula declares the test variable and initializes the value to false.
  • The second formula is placed in the details section of the report.  This formula tests for the condition and, if triggered, sets the test variable to true.  This formula uses the Crystal WhileReadingRecords function. 
  • The final formula evaluates the test variable.  If true, the header is made visible (with a warning message), otherwise it is hidden.  This function uses the Crystal EvaluateAfter function.
Here's exactly how it works.

Create a new formula called Declare Globals.  The code in this formula is as follows.  Place this formula in the header and make it invisible.  T is the test variable, and the test is initialized to false.

@Declare Globals code - placed in header

global booleanvar t;  // t is for test
t:= false;



Next, create another formula called Test Records.  In this example, the test is done in SQL, but it could be done in the report.  The only result of the test is to set the test variable to true if the test is triggered.  This code should be placed in the details section of the report and again made invisible.

@Test Records code - placed in details

global booleanvar t; // reference the variable declared in the header

whilereadingrecords;
if ({tblData.bad_data} = -1) then t := true;



Finally, go into Section Expert on the report and choose Report Header > Common tab > Suppress (No Drill Down).  Un-check Suppress and click the formula editor button next to Suppress.  Evaluate t and show/hide the report header based on the value of the test variable.  The report header should have the warning in it in big red letters to alert the user.

Code placed in the Report Header

global booleanvar t; // reference the variable declared in the header

evaluateafter({@Test Records});
not t;


18 May 2009

ASP.Net as Crystal Reports data source

There are not many good articles on using an ASP.Net web source as a data source.  This post attempts to enumerate the settings and make the process straightforward.

Before starting, I want to make a couple of recommendations:

  • In my experience, embedded schemas do not work.  That means that working with native types (such as DataSets) that have embedded schemas won’t work well.
  • Since embedded schemas don’t work, use a simple XMLDocument object as your return value.
  • You will need to write your own schema for service.  Again – keep the return XML simple.

The instructions for creating an Crystal Reports XML Data Source are as follows*:

  1. Open the database expert.  Choose Create New Connection / XML.
  2. XML (data source) type and location:  Choose enter in your service in the URL HTTP(S) XML URL textbox.  Check the box for Specify Schema File.  Click ‘Next’.  There are a couple of items to note here.
    • Crystal gives an option for choosing Use Web Service Data Source.  I cannot get this to work – don’t choose it.
    • The URL for the service is the .asmx path/service name.  For instance, if your service is getGrid on the web-apps server, the path is http://web-apps/services.asmx/getGrid.  Adjust the path as needed to your .asmx file.
  3. HTTP Authentication for XML file:  This screen deals with security.  I typically work inside a corporate firewall without security, so I leave these fields blank.  If necessary, fill in the User Id and Password.
  4. Schema file type and location:  I put my schema files on the server,  but usually test with a local XSD file.  Choose HTTP and the path, if the file is on your server.  Otherwise, if the file is local, choose Use Local Schema and point the path to the local schema.
  5. HTTP Parameters:  Click the Add Property … button to add your parameters.  The Value can be left blank, but the Property must be filled in with the parameter names.  Service parameters are case sensitive, so make sure that the case matches.
  6. Clicking Finish will take you back to the data screen.  You will be given an options for the XPaths to the data in your source.  If successful, you will then have data from a web service in your report.

---

* Tested on CR XI R2/CR 2008