Jump to content
Claris Engage 2025 - March 25-26 Austin Texas ×
The Claris Museum: The Vault of FileMaker Antiquities at Claris Engage 2025! ×

This topic is 7131 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Posted

Hi all,

I'm trying to write a Custom Function in FM Dev7 that has a parameter that references a field in a related table but of a different file. I'll bet there's a way of doing it but I can't figure it out for the life of me. Can someone clue me in, please?

Thanks in advance for your help! :)

Posted

In a custom function, the parameters are placeholders that will have values at the time the function is called. When calling a CF from within a calculation, you can pass static values, local field values, or related field values the same way as any built-in function:

MyField (calculation, text result) = MyFunction ( SomeTable::SomeField )

To use any field values within a custom function, you must pass them as parameters to the CF.

Posted

Hi Ender. Thanks for the quick response. The problem I run in to is that a parameter in CF's can't contain colons, among other things, therefore MyFunction ( SomeTable::SomeField ) won't work. Am I missing something in your answer?

Posted

As I said, the parameters are placeholders. Use non-reserved words for the parameters, and remember that they are local to that function:

Let's say we define a simple CF to return the nth character from a string of text. The CF would look something like:

charN ( text ; n ) =


middle ( text ; n ; 1 )

note that "text" is the name of the first parameter and "n" is the name of the second parameter. These parameters have nothing to do with real field names. They are temporary placeholders that will be populated when the function is called and something is passed to those parameters.

In a calculation we could use this function by passing fields as the parameters, or we might pass a text string and a number:

MiddleInitial (calculation, text result) = charN ( MiddleName ; 1)

or

RandomLetter (calculation, text result) = charN ( "ABCDEFGHIJKLMNOPQRSTUVWXYZ" ; int ( Random * 26 ) )

The point is, the CF definition does not have any references to fields in your database. It only knows about values you send in as parameters.

Posted

Oookay, I finally get it now! It's funny how sometimes you can get stuck on one track and not be able to see outside of it. In the dozen or so CF's I've written thus far I've always ensured that the parameter in the CF was a legit field name in the tables it would be used in. This worked fine until I wanted to create a parameter that was specifically the name "Table::fieldName" instead of just "fieldName", which as I said would be an actual field name.

So, I guess that my question changes a bit at this point. And please bear with me...since the parameter is just a placeholder, and doesn't necessarily reference a field name (although it can, which makes it very flexible and easy to use), can you think of a way for me to create a parameter or a calc that will add "Table::" onto the parameter's name, so that when I use that in a calc the only thing I have to do is insert it into the calc and click OK, and it'll work from there?

Posted

No, you will need to type the related field names into the CF calls.

I think the mistake you are making is that you are assuming your CF should be used only by one field. The CF should be written more generally so it can be used anywhere. This includes giving the parameters descriptive yet general names--not specific field names.

Posted

I see what you're saying about writing it more generally. I was definitely missing the bigger picture in that respect, as I was always writing it for one or more specific fields.

Thanks a bunch for all your help!!!

This topic is 7131 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.