Joined: 03 Dec 2012
Online Status: Offline
Posts: 6
Topic: Display string in Group Header text field Posted: 03 Dec 2012 at 6:14am
Hello. I'm not sure if this is the correct forum. I'm using Crystal Reports for .NET Framework 4.0 on Visual Studio 2010. I'm working with an existing report, which in its Group Header has a text field, i.e., Text6. This text field is located near the end of the report and until now has had hard-coded text, including dates for special rebate offers, which were modified yearly for the current offer.
However, beginning with 2013 there are going to be 2-separate offer dates and I want to programmatically evaluate which offer dates to use based on a particular storename.
I also need to know how to concatenate this string data for presentation in this text field and how to make portions of the text bolded.
I have a datatable which includes a field StoreName
I have included a sample of what I'm attempting but need assistance as this is my first time working with Crystal reports. Thank you.
Example text in Group Header Text field Text6:
Formula = "No Payment Received" + chrW(13)
Formula = Formula + "You failed to make a qualifying purchase." + chrW(13)
IF(ToText({Customer.StoreName}) = "Store A" Then
Formula = Formula + "Your request was received after the end of the Rebate timeframe - July 15, 2013." + chrW(13)
Formula = Formula + "You can resubmit your request as long as it is postmarked by July 22, 2013 " + chrW(13)
Formula = Formula + "and received by June 22, 2013." + chrW(13)
ELSE
Formula = Formula + "Your request was received after the end of the Rebate timeframe - February 24, 2013." + chrW(13)
Formula = Formula + "You can resubmit your request as long as it is postmarked by March 8, 2013 " + chrW(13)
Formula = Formula + "and received by March 22, 2013." + chrW(13) END IF
Joined: 19 May 2011
Online Status: Offline
Posts: 337
Posted: 03 Dec 2012 at 10:55am
well, there are a few ways you can do this, not sure if this is the best though.
I would create 3 text boxes (you can selectively bold text easily) -
in each
add your text in blocks
Text1
No Payment Received you failed to make a qualifying purchase.
** put this text box on top, and have both text2 and text3 overlapping eachother immediately below text1
-----
Text2
Your request was received after the end of the Rebate timeframe - July 15, 2013. You can resubmit your request as long as it is postmarked by July 22, 2013 and received by June 22, 2013.
Text 3
Your request was received after the end of the Rebate timeframe - February 24, 2013. You can resubmit your request as long as it is postmarked by March 8, 2013 and received by March 22, 2013.
For the text2 do a suppression formula using your logic
(ToText({Customer.StoreName}) = "Store A"
If this is true show text2
-----
For text3
(ToText({Customer.StoreName}) <> "Store A"
if this is not true show text3
Joined: 03 Dec 2012
Online Status: Offline
Posts: 6
Posted: 03 Dec 2012 at 11:17am
Thanks for the reply. However, I'm still not sure whether my syntax is correct though. I've tried a few different variations and each time I save it, CR complains that there is an error with the formula; although it doesn't tell me what the error might be. Is this the correct way to define a formula in CR? Or should I form it differently?
In addition, how do I make one text field conditionally visible or not visible?
Formula = "No Payment Received" & chrW(13)
Formula = Formula & "You failed to make a qualifying purchase." & chrW(13)
IF(ToText({Customer.StoreName}) = "Brookstone" Then
Formula = Formula & "Your request was received after the end of the Rebate timeframe - March 7, 2013." & chrW(13)
Formula = Formula & "You can resubmit your request as long as it is postmarked by March 12, 2013 " & chrW(13)
Formula = Formula & "and received by March 22, 2013." & chrW(13)
ELSE
Formula = Formula & "Your request was received after the end of the Rebate timeframe - February 24, 2013." & chrW(13)
Formula = Formula & "You can resubmit your request as long as it is postmarked by March 8, 2013 " & chrW(13)
Formula = Formula & "and received by March 22, 2013." & chrW(13)
END IF
Formula = Formula & "We hope you enjoy your Tempur-Pedic purchase and apologize for any inconvenience." & chrW(13)
Formula = Formula & "Sincerely," & chrW(13)
Formula = Formula & "Promotion Headquarters" Text6.text = Formula
Joined: 19 May 2011
Online Status: Offline
Posts: 337
Posted: 04 Dec 2012 at 3:13am
Originally posted by CodingMann
Formatting Is Much Different in Crystal Formula
go to Operators box, and look around.
you have to declare with a Scope (local/global/shared)
for a variable (shown in variable declarations).
Also:
-assign with := -break conditionals/statements with ;
Thanks for the reply. However, I'm still not sure whether my syntax is correct though. I've tried a few different variations and each time I save it, CR complains that there is an error with the formula; although it doesn't tell me what the error might be. Is this the correct way to define a formula in CR? Or should I form it differently?
In addition, how do I make one text field conditionally visible or not visible?
Formula = "No Payment Received" & chrW(13)
Formula = Formula & "You failed to make a qualifying purchase." & chrW(13)
IF(ToText({Customer.StoreName}) = "Brookstone" Then
Formula = Formula & "Your request was received after the end of the Rebate timeframe - March 7, 2013." & chrW(13)
Formula = Formula & "You can resubmit your request as long as it is postmarked by March 12, 2013 " & chrW(13)
Formula = Formula & "and received by March 22, 2013." & chrW(13)
ELSE
Formula = Formula & "Your request was received after the end of the Rebate timeframe - February 24, 2013." & chrW(13)
Formula = Formula & "You can resubmit your request as long as it is postmarked by March 8, 2013 " & chrW(13)
Formula = Formula & "and received by March 22, 2013." & chrW(13)
END IF
Formula = Formula & "We hope you enjoy your Tempur-Pedic purchase and apologize for any inconvenience." & chrW(13)
Formula = Formula & "Sincerely," & chrW(13)
Formula = Formula & "Promotion Headquarters"Text6.text = Formula
It isn't formatted correctly, you have to define a variable
local stringvar f1:='No Payment Received' + chr(10) + 'You failed to make a qualifying purchase.' + chr(10);
if (ToText({Customer.StoreName}) = "Brookstone" Then
f1:=f1+'Your request was received after the end of the Rebate timeframe - March 7, 2013.' + chr(10) + 'You can resubmit your request as long as it is postmarked by March 12, 2013' + chr(10) + 'and received by March 22, 2013.' + chr(10)
else
f1:=f1+'and received by March 22, 2013.' + chr(10) +
'You can resubmit your request as long as it is postmarked by March 8, 2013' + chr(10) + 'and received by March 22, 2013.' + chr(10);
f1:=f1+'We hope you enjoy your Tempur-Pedic purchase and apologize for any inconvenience.' + chr(10) +
'Sincerely,' + chr(10) + 'Promotion Headquarters';
Joined: 03 Dec 2012
Online Status: Offline
Posts: 6
Posted: 04 Dec 2012 at 10:33am
Thanks for the formatting tips. I created a new Formula Field I named "OfferDate", which has the following code:
global stringvar f1:='No Payment Received' + chr(10) + 'You failed to make a qualifying purchase.' + chr(10);
if (ToText({Customer.StoreName}) = "Store A") Then f1:=f1 + 'Your request was received after the end of the rebate timeframe - March 7, 2013.' + chr(10) + 'You can resubmit your request as long as it is postmarked on or before March 12, 2013' + chr(10) + 'and received by March 22, 2013.' + chr(10) else f1:=f1 + 'Your request was received after the end of the rebate timeframe - February 24, 2013.' + chr(10) + 'You can resubmit your request as long as it is postmarked on or before March 8, 2013' + chr(10) + 'and received by March 22, 2013.' + chr(10);
f1:=f1 + 'We hope you enjoy your purchase and apologize for any inconvenience.' + chr(10) + 'Sincerely,' + chr(10) + 'Promotion Headquarters';
After saving and closing the editor, I inserted this to text field Text6, which now has the following entry {@OfferDate}. However, NO Data appears in this PDF report when I run it. Also, if I click on the bottom where it reads "Main Report Preview" it displays this error: "This group section cannot be printed because its condition field is nonexistent or invalid. Format the section to choose another condition field."
Does any one know what I may be missing in the report or if I handled the Formula incorrectly? Thank you.
Joined: 19 May 2011
Online Status: Offline
Posts: 337
Posted: 05 Dec 2012 at 2:36am
you have to put the variable after the logic
so
declare
logic/assignment
;
f1
and I am not sure if you would want a globally defined variable. if this is, try shared.
local stringvar f1:='No Payment Received' + chr(10) + 'You failed to make a qualifying purchase.' + chr(10);
if (ToText({Customer.StoreName}) = "Brookstone" Then
f1:=f1+'Your request was received after the end of the Rebate timeframe - March 7, 2013.' + chr(10) + 'You can resubmit your request as long as it is postmarked by March 12, 2013' + chr(10) + 'and received by March 22, 2013.' + chr(10)
else
f1:=f1+'and received by March 22, 2013.' + chr(10) +
'You can resubmit your request as long as it is postmarked by March 8, 2013' + chr(10) + 'and received by March 22, 2013.' + chr(10);
f1:=f1+'We hope you enjoy your Tempur-Pedic purchase and apologize for any inconvenience.' + chr(10) +
'Sincerely,' + chr(10) + 'Promotion Headquarters';
Joined: 03 Dec 2012
Online Status: Offline
Posts: 6
Posted: 05 Dec 2012 at 9:32am
Well, I have implemented the suggestions as shown. However, my pdf report is blank. I inserted the formula field into the Text6 TextObject as explained earlier. Failing any data populating my report, I then tried deleting the Text field and inserting the formula directly to the report as a FieldObject and sizing it to the dimensions of the textobject, below existing TextObjects, as this is what is used above for the Addresses. However, my report continues to be blank.
Lastly, in my Visual Studio C# code, I added another column to the DataTable of type string, evaluated the StoreName being sent, and attempted to build a string message separated by "\r\n" and added this row to the datatable.Rows.
I created a new Formula Field I called "Offerings" with the formula of {Customer.OfferDate}. Again, I inserted this to the report and sized it accordingly. However, although I can see my code correctly evaluate the string message to use by store name, No Data appears in the report.
Can any one suggest what I'm missing in trying to implement this and get the report to populate? I'm at a loss here to know how to get this to work, short of actually creating a 2nd report similar to the original and hard-coding the text and dates and programmatically choosing the report to show by store.
Joined: 19 May 2011
Online Status: Offline
Posts: 337
Posted: 05 Dec 2012 at 9:45am
Originally posted by CodingMann
Well, I have implemented the suggestions as shown. However, my pdf report is blank. I inserted the formula field into the Text6 TextObject as explained earlier. Failing any data populating my report, I then tried deleting the Text field and inserting the formula directly to the report as a FieldObject and sizing it to the dimensions of the textobject, below existing TextObjects, as this is what is used above for the Addresses. However, my report continues to be blank.
Lastly, in my Visual Studio C# code, I added another column to the DataTable of type string, evaluated the StoreName being sent, and attempted to build a string message separated by "\r\n" and added this row to the datatable.Rows.
I created a new Formula Field I called "Offerings" with the formula of {Customer.OfferDate}. Again, I inserted this to the report and sized it accordingly. However, although I can see my code correctly evaluate the string message to use by store name, No Data appears in the report.
Can any one suggest what I'm missing in trying to implement this and get the report to populate? I'm at a loss here to know how to get this to work, short of actually creating a 2nd report similar to the original and hard-coding the text and dates and programmatically choosing the report to show by store.
Joined: 03 Dec 2012
Online Status: Offline
Posts: 6
Posted: 05 Dec 2012 at 10:30am
This is a letter with just a single record. In the Group Header.
As I have no prior experience with CR, can you explain the grouping you mentioned. Also, whether I insert the Formula as a FieldObject or insert the Formula into a TextObject, this appears near the end of the report and considering the height and width, there isn't much realestate on the form to implement much else.
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