Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Custom Function 2

Status
Not open for further replies.

BlurredVision

Technical User
Aug 6, 2001
326
GB
Hi All, I have just started working with CR10/Custom Functions.

Can I make the following formula a custom function?

{Med_Prof.Last_name} & ", " & {Med_Prof.First_name}

The function I created always wants me to re-enter the fields needed..

Thanks for your time!

Brian.
 
The easiest way is to use the extractor.

Save the above as a formula in a report.
In the formula workshop, click the down arrow next to the new button, and choose Custom Function.
Give it a name, then click the Use Extractor.
The Extract Custom Function from Formula dialog box will open.
Highlight the formula you saved above, anf fill out the information in the dialog. I recommend changeing the arguement names from v1 and v2 to something more meaningfule.
Perhaps LName and FName...
Click OK.
It places the function in the Report Custom Functions list.
If you want to add it to the repository, right click it and choose "Add to Repository"

To use the function in the report, create a new formula.
When you get to the editor, you will need to access the function from the Functions pane.
You will find it in the "Custom Functions" folder.
Double click to add it and supply the arguements to it the same as any built in function

~Brian
 
Thanks for your help Brian.. I'm beginning to understand. One more quick question on these things, then I believe I'll be set.

If I have a custom Function that list, say (FName, LastName, MInitial) and one of those values are null, the function doesn't return any information. Do you know of a way around this?

Thanks again!
 
You might try a conditional to build the function, as in:

if isnull({table.last})
or
{table.last}="" then
""
else
{table.last}+", "
+
if isnull({table.first})
or
{table.first}="" then
""
else
{table.first}+","
+
{table.initial}

-k
 
The problem is that you can't use a Print State function in a Custom Function.

This kind of defeats the purpose of using a Custom Function, as you would like to reuse this logic, but you can test for NULL's before calling the function:
Code:
stringvar MInit;

If IsNull({Med_Prof.middle_name}) then
    MInit := ""
Else
    MInit := {Med_Prof.middle_name};

ConcatName({Med_Prof.First_name},{Med_Prof.Last_name},MInit)



~Brian
 
I suppose I just think it's funny that the custom function will just fail if one of the fields are null within the Database. In the example I provided, not everyone will have a middle name, and if that's the case, the custom function will fail. I would have thought it would just provide the vaules it had available.
 
It handles it the same way that normal formulas handle NULL's. Any time it encounters and NULL value, it stops processing a returns a NULL.

~Brian
 
Hi Blurredvision,
what if you created a command using coalesce for the fields that could be null and base your report on this? This way you could use your custom function without worrying about whether or not there are nulls.

something like:

select coalesce(Med_Prof.Last_name,' ') as LName,
coalesce(Med_Prof.First_name,' ') as FName
from Med_Prof
 
Hi all,
Everyone is talking about using Extractors to create Custom Functions. I do not find Extractor anywhere on Crystal Report [in 10 and 9] versions. Can someone tell me where should i be looking for it?

Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top