Jump to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Passing field to custom function as object rather than the field's value

Featured Replies

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.

Isn't it in the vicinity of the scope of this article?

http://sixfriedrice.com/wp/set-field-by-name-exposed/

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 ) )

  • Author

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.

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.

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 )

)

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).

Create an account or sign in to comment

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.