kyle Posted January 3, 2003 Posted January 3, 2003 hi, can anyone lecture me on get field function ? is there any special reason why we need get field function ? what would be the best usage case of the get field function ? when do i need to use this function ? thanks, kyle
CobaltSky Posted January 3, 2003 Posted January 3, 2003 Hi Kyle, Well I don't know if I want to 'lecture' you exactly, but I don't mind telling you a bit about it! GetField( ) has a lot of possible uses. What it does is allows you to retrieve (in a script or calculation) the contents of a field without having to 'hard code' the name of the field to get the contents from. Instead, you use GetField( ) to tell FileMaker to look in a particular text field 'on the fly' to find the name of the field to get the value from. For example, one kind of use is where you want the user to be able to dynamically alter the outcome of a calculation by clicking on a radio button selection. If the radiobutton field has some fieldnames in it and you have a formula pointing to the checkbox via GetField( ) then selecting a different radio button causes a different field value to be input into the calculation. Try doing it without GetField and you'll likely end up with a page full of nested Case( ) and If( ) statements! Another similar example of the use of GetField( ) is in setting up dynamic sorting for small data sets (or portal data). If you use GetField( ) in a calc field to retrieve the value in a field the name of which is located in a global field, then set that calc field up as the primary sort field, you can change the field name in the global field (eg from a value list) in order to specify the sort order on-the-fly. ...Or you can point GetField( ) at a calculation field and have the sort order for your data determined by some logic that you code into a calculation! As the field based counterpart of the GetRepetition( ) function, GetField( ) really comes into its own when dealing with data arrays. You can build much more complex regression and stats analysis procedures if you can leverage data by referencing stored values according to calculated values. So for example, you can determine an average value from a set of input data (by calculation) and feed that result into a second calculation via GetField( ) to retrieve a value from a correspondingly named field. Based on a number of such calculations, you can produce a further result which again feeds into GefField( ) to reference another value. ...and so on, which give you the basis of a custom regression model. A slightly less well known (but neat!) use of GetField( ) is to break the 'circular relationship' barrier in cases where you want to be able to pass values back and forth without obstruction from FileMaker's table of dependencies. You need to know what you're about when doing this, but it allows you, for example, to set up two fields so that each has an auto entry option that depends on the other. One example that I mentioned in another post recently was to enable someone to set up both a metric and an imperial measurement data input field - and whichever you enter data into, the converted equivalent value is then auto-entered into the corresponding field. You enter in the metric field and the database auto-enters the calculated imperial equivalent in the imperial field and vice-versa. Made possible by a somwhat 'lateral' use of the capabilities of GetField( )! Along similar lines, GetField( ) can be used to force FileMaker to store index fields such as calculations which reference global or related fields. ...and once stored and indexed, such fields can be used as target keys for relationships, or as the basis of value lists etc. Again, you need to think through what you are doing before tackling this, or else the results may not be quite what is expected. But GetField( ) gives a level of power and flexibility to model data that can be difficult (perhaps in some cases impossible) to achieve any other way. There are many other possibilities, but hopefully the above has given you the gist of what it is good for?!
kyle Posted January 3, 2003 Author Posted January 3, 2003 hi, ray ! as usual, your post is so helpful. thanks. best regards, kyle
Ugo DI LUCA Posted July 15, 2003 Posted July 15, 2003 CobaltSky said: A slightly less well known (but neat!) use of GetField( ) is to break the 'circular relationship' barrier in cases where you want to be able to pass values back and forth without obstruction from FileMaker's table of dependencies. You need to know what you're about when doing this, but it allows you, for example, to set up two fields so that each has an auto entry option that depends on the other (.....) Made possible by a somwhat 'lateral' use of the capabilities of GetField( )! Ray, This is an old one but the unique thread that offered some "explanation" of this feature. I've been studying these GetField Capabilities and functions in the last days, but I went into total mess as it became a false "circular relationship", forcing me to either quit FM and (quite) delete the file itself... From what I understood, the GetField function offers a symetric way of doing things we usually are doing with the SetField script step SetField (field N, field N +5). What then may have been turning my calc to this nightmare and what exactly do you mean by "You need to know what you're about when doing this" ? Thanks.
kvt Posted July 24, 2003 Posted July 24, 2003 ooops press the wrong button. What I want to say is that, I have two fields - Formula of type text and Result of type Calculate. Formula = Purchase Cost + Shipping, these fields are also defined on the file as numbers, and Result = GetField(Formula). The output was blank? It seems that it does not understand the "+" operand. Any idea how the the formula will be executed and returns the value in the Result field?
-Queue- Posted July 24, 2003 Posted July 24, 2003 GetField(Formula) grabs the contents of the fieldname specified in the Formula field. In your case, two field names are in the formula field, so this is going to fail and return null. GetField("Formula") would return the result of Formula, though why exactly you need this instead of just using Formula itself, I'm not understanding.
kvt Posted July 24, 2003 Posted July 24, 2003 Yes, GetField(Formula) returns me the content of Formula. So Purchase Cost = 100 Shipping = 10 Formula = Purchase Cost + Shipping then Result = Purchase Cost + Shipping It doesn't calculates and returns 110 in the Result field. The reason for doing this is that I have a portal with columns (item, purchase cost, shipping, result, formula, etc.). Depends on the item selected (and other column criterias) a certain formula (from the list of formula or enter on the spot) is used to calculate the result column. So that's why I need to have a way of create the formula as in a text type, convert it into a calculate field and calculate the result. Hope that make sense.
-Queue- Posted July 24, 2003 Posted July 24, 2003 Try using multiple GetFields instead. Have globals called gPurchaseCost, gShipping, or whatever fields you might need. And when a different object is selected, set the contents of these global fields with the names of the fields that are appropriate for the current calculation. Then use GetField(gPurchaseCost) + GetField(gShipping), etc. Like I said before GetField(Formula) is automatically going to fail if you have anything more than one field name specified in it. It shouldn't be a calculation, just a single field name.
Recommended Posts
This topic is 7863 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 accountSign in
Already have an account? Sign in here.
Sign In Now