Writing Code
 Crystal Reports Forum : Crystal Reports for Visual Studio 2005 and Newer : Writing Code
Message Icon Topic: Crystal Report Alerts and reading report values in Post Reply Post New Topic
Author Message
shaurya.rastogi
Newbie
Newbie


Joined: 04 Feb 2007
Online Status: Offline
Posts: 6
Quote shaurya.rastogi Replybullet Topic: Crystal Report Alerts and reading report values in
    Posted: 07 Mar 2007 at 4:06am
I am workin on Crystal Reports for VS2005

1>Can i create alerts in it,if yes how?

2>How can i read values that are calculated by formula fields in the application code?
 
e.g there is a formula @Test i want to know what value it has in the code how do i do that.
 
If i use ReportDocument.DataDefinition.FormulaFields["@Test"].Text it shows me the content of formula i.e the code in formula.

Regards
Shaurya
IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
Quote hilfy Replybullet Posted: 07 Mar 2007 at 6:16am
What do you mean by alerts?
 
The type of the items in the FormulaFields collection is FormulaFieldDefinition, so you can't get a value from it, just the definition information.
 
The problem with getting the value of a formula field is that you can't get it while the report is processing.  Since most formulas operate at the record or group level, any value you might get is just the last one on the report which might not be the value you really need.  Brian may have a better answer, but I think the only way you can get to the actual value is to write SQL that duplicates how the formula works in the report and run that directly against the database to get the value.
 
-Dell
IP IP Logged
BrianBischof
Admin Group
Admin Group
Avatar

Joined: 09 Nov 2006
Online Status: Offline
Posts: 2458
Quote BrianBischof Replybullet Posted: 07 Mar 2007 at 10:11am
Dell is right that can't get the value while the report is processing. But it has more to do with the Crystal Reports object model. When you reference the report object, you are doing so prior to the report being processed. Thus, no formulas have values in them yet. But the second problem is that Crystal Reports simply doesn't expose any properties that tell you the value of a formula. It only returns the text of the formula, not the result. So there is nothing you can do except what Dell mentioned and that is duplicate the processing of the data in SQL and analyze the values with that resultset.

Now, considering that, if you want to get REALLY advanced, you could do something like create an updateable command object that writes a value to a special SQL table as the report runs. Then in your .NET app you can query the SQL table for that value. I haven't actually done this yet, but I'm going to be working on it soon so I can put an example in the book (should be pretty cool).
Please support the forum! Tell others by linking to it on your blog or website:<a href="http://www.crystalreportsbook.com/forum/">Crystal Reports Forum</a>
IP IP Logged
shaurya.rastogi
Newbie
Newbie


Joined: 04 Feb 2007
Online Status: Offline
Posts: 6
Quote shaurya.rastogi Replybullet Posted: 07 Mar 2007 at 8:37pm
Thanx for the response
 
1>By alerts i meant alerts in reports, i have seen provision for creating alerts in CR 11 but there exists no option for creating alerts in CS VS2005.
So the question is can we create alert in CR VS2005.
 
2>I will elaborate on the senario i have to deal with:
 
I have a formula field which calculates a Value Discrepancy.
If this value is less than a specified value i have to show an alert message.
 
Now , as i was unable to find the alert message functionality in CR what i planed on doin was to access the value of the formula in code and from there trigger a Message Box.
 
I have implemented this feature using a series of SQL queries but it increases the code and all the calculation implemented on reports have to be replicated in code also.
 
 
So, do u think that i can avoid the processing in the code by any means by either adding alerts somehow or by accessing the value from within the report.
 
Thankyou
Shaurya
 
IP IP Logged
BrianBischof
Admin Group
Admin Group
Avatar

Joined: 09 Nov 2006
Online Status: Offline
Posts: 2458
Quote BrianBischof Replybullet Posted: 07 Mar 2007 at 9:18pm
I see what you are talking about. Unfortunately, Visual Studio CR 2005 doesn't have report alerts. If you have access to CR XI, then you can build the report in XI and call it from VS 2005. This will let you do alerts. Otherwise, you are stuck with you SQL workaround.
Please support the forum! Tell others by linking to it on your blog or website:<a href="http://www.crystalreportsbook.com/forum/">Crystal Reports Forum</a>
IP IP Logged
shaurya.rastogi
Newbie
Newbie


Joined: 04 Feb 2007
Online Status: Offline
Posts: 6
Quote shaurya.rastogi Replybullet Posted: 14 Mar 2007 at 2:22am

Finally i found the solution to my problem so i am sharing the solution here.

The values that are printed on the report can be accessed from the code by this code.

CrystalDecisions.CrystalReports.Engine.ReportDocument a = new CrystalDecisions.CrystalReports.Engine.ReportDocument();

str value=a.Rows[0][20].ToString();

The Rows property contains the data on the front page of the report.
IP IP Logged
BrianBischof
Admin Group
Admin Group
Avatar

Joined: 09 Nov 2006
Online Status: Offline
Posts: 2458
Quote BrianBischof Replybullet Posted: 14 Mar 2007 at 9:09am
I'm not familiar with the Rows property of the report object. That must be new for 2005. I'll have to look into it. Thanks for the update!
Please support the forum! Tell others by linking to it on your blog or website:<a href="http://www.crystalreportsbook.com/forum/">Crystal Reports Forum</a>
IP IP Logged
Post Reply Post New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum



This page was generated in 0.031 seconds.