Jump to content

GetFieldName ( fieldName ) - the missing function


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

Recommended Posts

Hi all friends

as I'm a ChindoguMaker :)

I need this function !

But it isn't so simple to explain the "WHY" !

So I wish to point the right direction with the file attached.

ANTEFACTA: with a large number of FileMaker function

you can retrieve a field contents, but there is no one

to retrieve the field name.

"You are a lying man !" (you can say)..."there is one:

Get ( ActiveFieldName )"

Suddenly I'll explain why this isn't the same I wish.

PURPOSE: the only situation that need this function

is when you make a custom function that needs the

field name as a parameter.

A simple one that I can think is:

________________________________________________________________________

/*Field'sAllContents ( fieldName ; start )

this retrieve the contents of a field in a found set

starting from record "start" and generates a list

*/

GetNthRecord ( fieldName ; start) &

Case (

start < Get ( FoundCount ) ; "¶" & Field'sAllContents ( fieldName ; start + 1 );

""

)

________________________________________________________________________

This custom works without the need of the field name, but only because

GetNthRecord() has fieldName as first parameter and not field contents !!

So we go on with another custom...

________________________________________________________________________

/*Syncronise ( fieldName1 ; fielName2 )

this syncronise the fieldName1's contents with fieldName2's contents

*/

Let([

fieldName = Get ( ActiveFieldName )

];

Case(

fieldName = "fieldName1" ; fieldName1 ;

fieldName2

)

)

________________________________________________________________________

This custom works, but it needs a field name, so I have to hardcode it !!

( look at "fieldName1" part of the function ... if the missing function didn't miss

I could write instead: GetFieldName ( fieldName1 ) !! )

As the function is missing, the custom will work only if the field: fieldName1 really exists in the DB !

GetFieldName.zip

Link to comment
Share on other sites

This is one tricky problem!! The only places to my knowledge where you can persuade FMP to give you a fieldname in response to a function are via Get(ActiveFieldName) and the FieldNames function. I don't know how to persuade a field to become active from within a function so lets look at the other method.

What I am going to propose is a partial solution. I uses a helper function which recurses down through a list of fieldnames until it finds a field with the same content and then it returns that fieldname - which may not be the one you are looking for. I did say it was partial. There alaso appear to be problems if the field is empty so I've pulled that out at the start.

TestFieldName(field;values;n) =

Case(

field=""; "Indeterminate";

Let([n = ValueCount(values); $c = RightValues(values;1)];

Case(

n = 1; $c;

If(field = GetField(NCR($c));NCR($c);

TestFieldName(field;LeftValues(values;n-1);n-1)))))

In this definition there is one other custom function NCR which removes the final carriage return from a value.

NCR(field) =

If(Right(field;1) = "¶";Left(field;Length(field) - 1);field)

and then GFN (I'll not call it GetFieldName since it is incomplete.

GFN(field) =

TestFieldName(field;FieldNames(Get(FileName);"");ValueCount(FieldNames(Get(FileName);"")))

This simply checks through the fields in the current file. I have only used it with the sample file you put up; that has a small number of fields and only one table. It may be that if you are using fields on a single layout that you should put in the Layout name parameter in the FieldNames function.

Link to comment
Share on other sites

I am not sure you are attacking the right problem. I am also not sure Daniele's example is the best one (or perhaps I don't understand him, after all...).

Let me see if I can demonstrate this better. Here's a simple (and not very reliable) custom function:

LastRepetitionExposed ( repeatingField ; counter ) =

Case (

GetRepetition ( repeatingField ; counter ) = Last ( repeatingField ) ; counter ;

LastRepetitionExposed ( repeatingField ; counter + 1 )

)

This will return the number of the last repetition of repeatingField (or an earlier one, if its contents equal the last).

But I want to get rid of the counter parameter, which is of no concern to the user, and should not be exposed. I want the function to have the form of:

LastRepetition ( repeatingField )

Now, ostensibly we could hide the counter in the parameter itself, using the piggyback method discussed here. So the function would go something like:

Let ( [

realParameter = Substitute ( LeftValues ( repeatingField ; 1 ) ; ¶ ; "" ) ;

piggybackCounter = 1 + MiddleValues ( repeatingField ; 2 ; 1 )

] ;

Case (

GetRepetition ( realParameter ; piggybackCounter ) = Last ( realParameter ) ; piggybackCounter ;

LastRepetition ( realParameter & ¶ & piggybackCounter + 1 )

)

)

And here's the problem: even in the first iteration, realParameter is evaluated using the CONTENTS of repeatingField. There seem to be no way to tell Filemaker "this is a NAME of a field, to be used in a function requiring a field name. Please keep it as text, do not evaluate it".

Link to comment
Share on other sites

Ok. What my CF does is solve the following possibly related problem. If field is not empty then the CF produces the name of a field with matching content. Not the same thing as producing the name of the field I agree but a step in the right direction I think, as it does produce the name of a field.

The first step in solving a problem like this is to demonstrate that a solution is possible or might be possible and without an explicit solution the best way to do that is to produce a franework under which the possibility of a solution seems reasonable. Once you have established that then the expert coders can get to work and produce an efficient solution.

In this problem we have not yet established that it is possible to produce a solution. That is, given a field as a parameter in a function deliver the name of the field. To my simplistic mind the obvious thing to do is:

1. Make the field active.

2. Read its fieldname from Get(ActiveFieldName)

Unfortunately I have absolutely no idea how to do step 1 within a CF and hence do idea whether step 2 will work if you can do step one. Another method is to make the contents of field unique somehow (from within the CF) then find the name of the field from my suggestion and finally replace the contents of field once you have its fieldname. Again I don't know how to do this.

Link to comment
Share on other sites

Another method is to make the contents of field unique somehow (from within the CF) then find the name of the field from my suggestion and finally replace the contents of field once you have its fieldname.

Humm...

This seems an interesting method !

I'll make some study about this ! ;)

Link to comment
Share on other sites

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