November 30, 201114 yr 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.
November 30, 201114 yr Isn't it in the vicinity of the scope of this article? http://sixfriedrice.com/wp/set-field-by-name-exposed/
November 30, 201114 yr 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 ) )
November 30, 201114 yr 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.
November 30, 201114 yr 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.
November 30, 201114 yr 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 ) )
November 30, 201114 yr 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