Solved

crystal display string

Posted on 2010-09-20
17
484 Views
Last Modified: 2012-05-10
I just want to add a asterisk on the end of a string value if it meets a criteria and if it doesn't I want to return the original value.  Here is my code under display string for the field I am working on.  What happens is that the else statement return blank.

if {Command.RECIPE_LINES_PART_CODE} <> "" then
{Command.PART_CODE}+ "*"
else  ({Command.PART_CODE})

0
Comment
Question by:Amerilab
  • 5
  • 3
  • 3
  • +3
17 Comments
 
LVL 26

Expert Comment

by:Kurt Reinhardt
ID: 33719916
Try the following:

If
  (
  Not (IsNull({Command.RECIPE_LINES_PART_CODE}))
  OR {Command.RECIPE_LINES_PART_CODE} <> ""
  )
Then
//as a force of habit, I alway use an ampersand to concatenate objects, since the + only works between strings, but & works with all datatypes
  {Command.PART_CODE} & "*"
Else
  {Command.PART_CODE}

Also, have you verified that {Command.PART_CODE} really has data for the records in question?

~Kurt
0
 

Author Comment

by:Amerilab
ID: 33719961
yes it does.  When I put in the code it blanks out the one that doesn't meet the first criteria.

Tried it same result.
0
 
LVL 26

Expert Comment

by:Kurt Reinhardt
ID: 33720102
That's odd.  The code basically says: If field 1 exists, then concatenate field 2 with * otherwise field 2 by itself. You're saying field 2 exists in this scenario, even if field 1 doesn't?

1)  Is all the code in a single command or are there multiple commands/table joins?
2)  Are you running this comparison in the detail section of the report or in a header/footer?

~Kurt
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

Author Comment

by:Amerilab
ID: 33720131
I am running it right on the field in the report.   If I have nothing in the display string code then all data comes up.  But when I put it back in the report only show some of the data.  The data that meets the first criteria.  
0
 
LVL 100

Expert Comment

by:mlmcc
ID: 33722075
Add WhilePrintingRecords; as the first line.

If you don't use that it may evaluate it early.

mlmcc
0
 
LVL 19

Expert Comment

by:GJParker
ID: 33723747
Instead of using the display string formula add a new formula and place thsi and teh 2 fields recipe_lines_part_code and part_code onto your report and show us a screenshot of teh report indicating which records are returning the wrong results.
0
 
LVL 34

Accepted Solution

by:
James0628 earned 250 total points
ID: 33732272
I think Kurt may be right about nulls being the issue, but I also think he got some of the logic wrong.  I believe what he posted is saying if RECIPE_LINES_PART_CODE is not null or is not "".  Since it can't be both null and "", it will always _not_ be one or the other, so the ELSE will never be executed.  Try this:

if not IsNull ({Command.RECIPE_LINES_PART_CODE}) and
 {Command.RECIPE_LINES_PART_CODE} <> "" then
{Command.PART_CODE}+ "*"
else  ({Command.PART_CODE})


 I'm assuming that you want to treat a null like an empty string, so that says if the field is not null and not the empty string, add the "*", otherwise don't add the "*".

 James
0
 
LVL 4

Expert Comment

by:msd1305
ID: 33732848
go to File->Report Options.

Select "Convert Database NULL values to default" and "Convert otjer NULL values to default" . This will replace your null values with proper values i.e. NULL string with "" and NULL integer with 0.
0
 
LVL 34

Expert Comment

by:James0628
ID: 33734094
msd1305 has a good point.  If nulls are the problem, that would be another way to handle this.  Actually, it's what I would usually do for something like this.  I guess I was too focused on the formula to think of it.  :-)

 James
0
 
LVL 4

Expert Comment

by:msd1305
ID: 33737434
Amerilab, dont u think u should have accepted my comment as the solution??
0
 

Author Comment

by:Amerilab
ID: 33737489
Yes.  I apologize.  I accepted the wrong one.  Is there anyway to change this?  
0
 

Author Comment

by:Amerilab
ID: 33737604
How do I change the accepted answer?
0
 
LVL 26

Expert Comment

by:Kurt Reinhardt
ID: 33738817
If anything, I suggest you split points between at least James and msd1305.  The issue, based on your acceptance, was obviously due to NULLs.  James corrected the syntax in my original suggestion, which accounted for both NULLs and empty strings.  MSD1305's converts NULLs to empty strings - both accomplish the same thing.

Regardless, I actually recommend against converting NULLs to empty strings. There's a specific scenario in which Crystal Reports will erroneously filter out records based on that setting.  It involves  having  parameter against the field that contains NULL values.  That specific scenario may not apply to this report, but it's good to know about as a "best practices" rule of report design (the issue has existed in every version of Crystal Reports since at least 8 - 2008).  Here are some links that demonstrate the problem:

https://www.box.net/shared/yd65ff3k8h (sample report)
https://docs.google.com/present/view?id=ddcfj5p5_78fbcxb9cz (explained in this presentation from the 2009 conference)

~Kurt
0
 
LVL 4

Assisted Solution

by:msd1305
msd1305 earned 250 total points
ID: 33740846
I went through the document though I do not really see it as a disadvantage considering the problem we face when formulas dont work properly with NULL values (even the isnul()l function does not always work as it should be ) and we end up wasting lot of time to find out the reason.
0
 
LVL 100

Expert Comment

by:mlmcc
ID: 33759375
Just accept the comments you want

http://www.experts-exchange.com/help.jsp#hs=29&hi=407

mlmcc
0
 

Author Closing Comment

by:Amerilab
ID: 33932461
Thanks
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Crystal Reports: 5 Tests for Top Performance It is complete, your masterpiece report.  Not only does it meet your customer’s expectations, it blows them out the water, all they want is beautifully summarised and displayed in a myriad of ways. …
Hot fix for .Net Crystal Reports 10.2.3600.0 to fix problems with sub reports running on 64 bit operating systems ISSUE: Reports which contain subreports fail with error "Missing Parameter Value" DEPLOYMENT SERVER OS: Windows 2008 with 64 bi…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question