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 4799 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Posted

This is something I've been wondering about for a while.

It's obvious that there's a difference between how some FM functions work compared to others. For example, when you say ABS( some::field ), it returns the absolute value of the value of that field. However, when you use GetFieldName( some::field ), it doesn't use the value of the field, but rather the properties of the field itself. This is fantastically useful.

So is there any way that I can make a custom function that acts like GetFieldName? Let's say I want to write a simple function that extracts the database name of a field that I pass in. It would be great if I could just call the function like GetDBName( some::field ) and have it know that it needs to parse the field name property of the field rather than using the value in the field.

Posted

You are right that Filemaker is inconsistent in the way it distinguishes between a field value and a reference to the field itself. However, the parameters of a custom function will always be interpreted as values.

You still can send a field name (as a text string) to your function, and use GetField() to convert it to a reference. To protect against future changes in the field's name, call your function as =

MyCustomFunction ( GetFieldName ( MyField ) )

Posted

Soren: Close, but not really. What I'm interested in is passing the field reference to a custom function rather than a script.

comment: Thanks. I figured as much, and what you suggested is what I've been using. I was just wondering if there's an easier way. Hopefully this will be added in a later version of FM! Also, I believe that GetField( myField ) doesn't convert it to a reference, but rather gets the contents of myField.

Posted

I believe that GetField( myField ) doesn't convert it to a reference, but rather gets the contents of myField.

No, that's not quite accurate. GetField ( MyField ) converts the contents of MyField into a reference. GetField ( "MyField" ) converts the text string "MyField" into a reference to the MyField field - and a reference to a field is evaluated as the field contents.

Posted

However, the parameters of a custom function will always be interpreted as values.

This is incorrect. Consider this custom function, which takes a field (*not* a field name) as a parameter: https://github.com/f...meVariable.fmfn


// GetFieldNameVariable ( field ; prefix )

// Example use (in field auto-enter calculation): GetFieldNameVariable ( Self ; "$" )

Let ( [

var.field = GetFieldName ( field );

var.parts = Substitute ( var.field ; "::" ; ¶ );

var.result = Evaluate ( prefix & GetValue ( var.parts ; 2 ) )

];

If ( var.result = "?" ; False ; var.result )

)





The fact that the "GetFieldName ( field )" line works in this function suggests that a custom function argument is capable of acting as a reference. Getting back to what I assume Quartekoen was mentioning as a starting example, this custom function along the same lines also works:





// GetTableName ( field )

Let ( [

~name = GetFieldName ( field );

~values = Substitute ( ~name ; "::" ; ¶ )

];

GetValue ( ~values ; 1 )

)

Posted

This is incorrect.

Yes, you are right. There are a few functions that will interpret a parameter as a field reference (that's what I meant by Filemaker being inconsistent).

This topic is 4799 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.