dbTalk Databases Forums  

use field names as script parameters

comp.databases.filemaker comp.databases.filemaker


Discuss use field names as script parameters in the comp.databases.filemaker forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
MaximalVariance
 
Posts: n/a

Default use field names as script parameters - 06-07-2007 , 08:41 AM






Hello--

I have a situation where I want the same script executed iteratively
over all fields (+500) in one particular table. (These are all
molecular structures in the same pathway and they do all belong in one
table). I am comparing the values in each field to related values in
another table, where the two tables are related by person ID. If there
is any difference between these two tables, I would like the value of
a third table to store a message like 'error' or 'match' for each of
the 500 variables. This part is all easy enough, my only dilemma is in
not wanting to hard code the variable names multiple times into each
of the scripts for each comparison. So, to summarize, has anyone
succesfully passed the field names in a databases defintion as script
parameters? Something pseudo code-ish to a "for each field y in table
x...{logic here}" where i can dynamically populate the "y's" in the
previous line.

thanks for any thoughts.

-sg


Reply With Quote
  #2  
Old   
Helpful Harry
 
Posts: n/a

Default Re: use field names as script parameters - 06-08-2007 , 01:08 AM






In article <1181223683.766613.23930 (AT) q69g2000hsb (DOT) googlegroups.com>,
MaximalVariance <StephenTGallagher (AT) gmail (DOT) com> wrote:

Quote:
Hello--

I have a situation where I want the same script executed iteratively
over all fields (+500) in one particular table. (These are all
molecular structures in the same pathway and they do all belong in one
table). I am comparing the values in each field to related values in
another table, where the two tables are related by person ID. If there
is any difference between these two tables, I would like the value of
a third table to store a message like 'error' or 'match' for each of
the 500 variables. This part is all easy enough, my only dilemma is in
not wanting to hard code the variable names multiple times into each
of the scripts for each comparison. So, to summarize, has anyone
succesfully passed the field names in a databases defintion as script
parameters? Something pseudo code-ish to a "for each field y in table
x...{logic here}" where i can dynamically populate the "y's" in the
previous line.

thanks for any thoughts.
You don't say what version of FileMaker, but it may make no difference
anyway since I doubt this can be done ... then again there may well be
something in newer versions of Filemaker that someone else can point
you to.


I'm also not sure if you mean 500 fields in a record or 500 fields in a
table (1 field in multiple records) - i'd guess the first since the
second makes it quite easy to do what you want to do.


If you mean 500 fields in one RECORD, then you would probably have been
better to use a separate related table - one record for each of the
fields you've currently got. This would then have made the process
relatively easy since you can loop through the Portal rows or go to the
related table and loop through the records themselves.

You could even have used {shudder} a repeating field with 500 repeats
which are then easy to loop through using the Get Repetition function
.... but they're a pain to set the value of via a script since there is
no Set Repetition function.


If you mean 500 fields in a table, then you can simply loop through the
records testing the same field.
ie.
Go To Record [First]
Loop
If Field X = Table2::FieldY
Set Field [Result, "Match"]
Else
Set Field [Result, "Error"]
End If
Go To Record [Next, Exit after Last]
End Loop


Helpful Harry
Hopefully helping harassed humans happily handle handiwork hardships ;o)


Reply With Quote
  #3  
Old   
Helpful Harry
 
Posts: n/a

Default Re: use field names as script parameters - 06-08-2007 , 02:46 AM



In article <4668fe4e$0$79829$dbd43001 (AT) news (DOT) wanadoo.nl>, "Ursus"
<ursus.kirk (AT) wanadoo (DOT) nl> wrote:

Quote:
"MaximalVariance" <StephenTGallagher (AT) gmail (DOT) com> schreef in bericht
news:1181223683.766613.23930 (AT) q69g2000hsb (DOT) googlegroups.com...
Hello--

I have a situation where I want the same script executed iteratively
over all fields (+500) in one particular table. (These are all
molecular structures in the same pathway and they do all belong in one
table). I am comparing the values in each field to related values in
another table, where the two tables are related by person ID. If there
is any difference between these two tables, I would like the value of
a third table to store a message like 'error' or 'match' for each of
the 500 variables. This part is all easy enough, my only dilemma is in
not wanting to hard code the variable names multiple times into each
of the scripts for each comparison. So, to summarize, has anyone
succesfully passed the field names in a databases defintion as script
parameters? Something pseudo code-ish to a "for each field y in table
x...{logic here}" where i can dynamically populate the "y's" in the
previous line.

thanks for any thoughts.

Presume you have at least version 7, but better 8.5.

It has a nice function
FieldNames(fileName;layoutName)Create a layout with all fields on it (easy
enough) <AllFields
Goto that layout
create a calc Fieldnames ( Get ( Filename) ; "AllFields" )
this will return a return delimited list with all FieldNames.
Easy enough to store and reuse, looping through the list.

Keep well, Ursus
The FieldNames function has been there since at least FileMaker 4, but
unfortunately I can't see it being of any use for this problem.

Although that will let you obtain a list of the names of the fields,
you can't actually use those names within other functions in place of a
field - you can't, for example, use

Set Field [VariableField, "5"]

where VariableField can take on any of the real field names that you
want to set the value of. This means you can't set the value of all
five fields called:

Field_1, Field_2, Field_3, Field_4, Field_5

by using a loop like

Set Parameter [Variable, 1]
Loop
Set Field ["Field_" & Variable, "My Value"]
Set Parameter [Variable, Variable + 1]
Exit Loop If [Variable = 6]
End Loop

You instead have to hardcode the Set Field command five times with the
actual field names.
ie.
Set Field [Field_1, "My Value"]
Set Field [Field_2, "My Value"]
Set Field [Field_3, "My Value"]
Set Field [Field_4, "My Value"]
Set Field [Field_5, "My Value"]



Helpful Harry
Hopefully helping harassed humans happily handle handiwork hardships ;o)


Reply With Quote
  #4  
Old   
Howard Schlossberg
 
Posts: n/a

Default Re: use field names as script parameters - 06-08-2007 , 09:28 AM



Helpful Harry wrote:
Quote:
The FieldNames function has been there since at least FileMaker 4, but
unfortunately I can't see it being of any use for this problem.
But suppose you had all your target fields on a special layout. Go to
the first field and make note of what it is (using Get(ActiveFieldName)
so you know where you began your journey). Then loop through all fields
on the layout (using Go To Next Field) until you come back to the
starting point. At each stop along the way you can set the field with
something like:

Set Field [no target field specified;
GetField ("RelatedTable::" & Get(ActiveFieldName)) ]

Note that "Get(ActiveFieldName)" was "Status(CurrentFieldName)" in
version 6 and maybe 5.5.


--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Howard Schlossberg
FM Professional Solutions, Inc. Los Angeles

FileMaker 8 Certified Developer
Member, FileMaker Business Alliance


Reply With Quote
  #5  
Old   
Grip
 
Posts: n/a

Default Re: use field names as script parameters - 06-08-2007 , 10:18 AM



On Jun 7, 7:41 am, MaximalVariance <StephenTGallag... (AT) gmail (DOT) com>
wrote:
Quote:
Hello--

I have a situation where I want the same script executed iteratively
over all fields (+500) in one particular table. (These are all
molecular structures in the same pathway and they do all belong in one
table). I am comparing the values in each field to related values in
another table, where the two tables are related by person ID. If there
is any difference between these two tables, I would like the value of
a third table to store a message like 'error' or 'match' for each of
the 500 variables. This part is all easy enough, my only dilemma is in
not wanting to hard code the variable names multiple times into each
of the scripts for each comparison. So, to summarize, has anyone
succesfully passed the field names in a databases defintion as script
parameters? Something pseudo code-ish to a "for each field y in table
x...{logic here}" where i can dynamically populate the "y's" in the
previous line.

thanks for any thoughts.

-sg
I know you think you need 500 fields in one record, but really you're
probably better off with a table of Structures with 500 records per
record in the table Pathways.

Regardless, I think Ursus is correct. Set Field dynamically is not
needed here. Here's what I would do...create a repeating field with
500 reps. Loop through the field list setting the repetition number
of the repeating field to a combo of fieldName & "|" & result.

You can then import that repeating field into your third table,
splitting the reps into new records.

G




Reply With Quote
  #6  
Old   
Grip
 
Posts: n/a

Default Re: use field names as script parameters - 06-08-2007 , 10:44 AM



On Jun 8, 8:28 am, Howard Schlossberg
<how... (AT) nospam (DOT) fmprosolutions.com> wrote:
Quote:
Helpful Harry wrote:

The FieldNames function has been there since at least FileMaker 4, but
unfortunately I can't see it being of any use for this problem.

But suppose you had all your target fields on a special layout. Go to
the first field and make note of what it is (using Get(ActiveFieldName)
so you know where you began your journey). Then loop through all fields
on the layout (using Go To Next Field) until you come back to the
starting point. At each stop along the way you can set the field with
something like:

Set Field [no target field specified;
GetField ("RelatedTable::" & Get(ActiveFieldName)) ]

Note that "Get(ActiveFieldName)" was "Status(CurrentFieldName)" in
version 6 and maybe 5.5.

--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Howard Schlossberg
FM Professional Solutions, Inc. Los Angeles

FileMaker 8 Certified Developer
Member, FileMaker Business Alliance
This thread got me thinking. This post may not make complete sense as
I'm still working on the idea and it's still morning where I am and I
haven't had my coffee. Maybe someone's already come up with this way
of Set Field by indirection or it's too unwieldy to be useful...

While Set Field [field name] doesn't access the calc engine, choosing
the repetition number does. So I could create a repeating field
(RepField) and map each field in a table that I might want to Set
Field to a repetition in that field in two ways. One is to make it
auto-enter always replace with GetRepetition(RepField; x). The other
is to embed x into the field somewhere, probably in the name itself
(Field1, Field2, Fieldx).

Then whenever I want to Set Field by indirection, say I've captured a
field name in $field, I Set Field[RepField [GetAsNumber($field)]].

Thoughts?

G



Reply With Quote
  #7  
Old   
Helpful Harry
 
Posts: n/a

Default Re: use field names as script parameters - 06-08-2007 , 06:45 PM



In article <46698c92$0$95239$dbd49001 (AT) news (DOT) wanadoo.nl>, "Ursus"
<ursus.kirk (AT) wanadoo (DOT) nl> wrote:

Quote:
The FieldNames function has been there since at least FileMaker 4, but
unfortunately I can't see it being of any use for this problem.

Although that will let you obtain a list of the names of the fields,
you can't actually use those names within other functions in place of a
field - you can't, for example, use

Set Field [VariableField, "5"]

where VariableField can take on any of the real field names that you
want to set the value of. This means you can't set the value of all
five fields called:

Field_1, Field_2, Field_3, Field_4, Field_5

by using a loop like

Set Parameter [Variable, 1]
Loop
Set Field ["Field_" & Variable, "My Value"]
Set Parameter [Variable, Variable + 1]
Exit Loop If [Variable = 6]
End Loop

You instead have to hardcode the Set Field command five times with the
actual field names.
ie.
Set Field [Field_1, "My Value"]
Set Field [Field_2, "My Value"]
Set Field [Field_3, "My Value"]
Set Field [Field_4, "My Value"]
Set Field [Field_5, "My Value"]

Harry, the OP was talking about script parameters. With 8 you can set a
variable and use this

Set Variable <$MyVariable ; MyValue
Perform Scipt <Somescript ; $MyVariable

Now you see how the variable can hold any value from the list with
fieldnmames and parse it to a second script as scriptparameter.
Yes variables are useful, but they were also wanting to use those
parameters within other functions in place of field names to access the
field's data, which as far as I can work out (and may well be wrong of
course) is not possible,
eg.
Set Field [$MyVariable, "My Value"]

or If ($MyVariable = "My Value", "Yes", "No")

where $MyVariable contains the name of a field and you want to set or
retrieve the actual data value of that field.

For example, if $MyVariable contains "MyField_1" using the above Set
Field command will not set the data of MyField_1 to "My Value". Or in
the second example the If statement will test the contents of
$MyVariable, not the contents of the field MyField_1. Both are likely
produces a "Field name expected" error when trying to exit the script /
calculation.

The way around this may be to use the variable (or a temporary field)
to store each fields value as you loop through copying the data values
from each field in sequence, but it would be a long-winded process for
500 fields. I think the best answer is more likely to be to separate
those fields into 500 records in another table.











Helpful Harry
Hopefully helping harassed humans happily handle handiwork hardships ;o)


Reply With Quote
  #8  
Old   
Helpful Harry
 
Posts: n/a

Default Re: use field names as script parameters - 06-08-2007 , 06:47 PM



In article <136ips4gsogtp94 (AT) corp (DOT) supernews.com>, Howard Schlossberg
<howard (AT) nospam (DOT) fmprosolutions.com> wrote:

Quote:
Helpful Harry wrote:

The FieldNames function has been there since at least FileMaker 4, but
unfortunately I can't see it being of any use for this problem.

But suppose you had all your target fields on a special layout. Go to
the first field and make note of what it is (using Get(ActiveFieldName)
so you know where you began your journey). Then loop through all fields
on the layout (using Go To Next Field) until you come back to the
starting point. At each stop along the way you can set the field with
something like:

Set Field [no target field specified;
GetField ("RelatedTable::" & Get(ActiveFieldName)) ]

Note that "Get(ActiveFieldName)" was "Status(CurrentFieldName)" in
version 6 and maybe 5.5.
Status(CurrentFieldName) is available in at least FileMaker 4 - I no
longer have FileMaker 3 to check that. )

But it's not going to help here unless you're going to loop through all
500 fields and setting a temporary field to use within If statement
tests ... ALTHOUGH I see you're using a GetField command that does seem
to work as the original person wanted, so maybe it is possible in newer
versions of FileMaker to do something like:

If (GetField($MyVariable) = "My Value", "Yes", "No")

where it tests the data stored in the field MyField_1 when $MyVariable
contains "MyField_1".

If this is the case then it is the answer to the original question,
although it's still a long winded approach that may be better off being
changed to use a separate table with 500 records rather than 500
fields.


Helpful Harry
Hopefully helping harassed humans happily handle handiwork hardships ;o)


Reply With Quote
  #9  
Old   
Howard Schlossberg
 
Posts: n/a

Default Re: use field names as script parameters - 06-08-2007 , 07:00 PM



Helpful Harry wrote:

Quote:
If this is the case then it is the answer to the original question,
although it's still a long winded approach that may be better off being
changed to use a separate table with 500 records rather than 500
fields.
I'm not sure I understand what is long-winded about it. I can write
this script in about seven steps. I challenge you to do it in fewer.


Go to Next Field
Set Variable [$Start; Get(ActiveFieldName) ]
Loop
Set Field [no target field specified;
GetField ("RelatedTable::" & Get(ActiveFieldName)) ]
Go to Next Field
Exit Loop If [ $Start = Get(ActiveFieldName) ]
End Loop

--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Howard Schlossberg (818) 883-2846
FM Professional Solutions, Inc. Los Angeles

FileMaker 8 Certified Developer
Associate Member, FileMaker Solutions Alliance


Reply With Quote
  #10  
Old   
Helpful Harry
 
Posts: n/a

Default Re: use field names as script parameters - 06-09-2007 , 01:19 AM



In article <136jr9v8gmq7naa (AT) corp (DOT) supernews.com>, Howard Schlossberg
<howard (AT) antispahm (DOT) fmprosolutions.com> wrote:

Quote:
Helpful Harry wrote:

If this is the case then it is the answer to the original question,
although it's still a long winded approach that may be better off being
changed to use a separate table with 500 records rather than 500
fields.

I'm not sure I understand what is long-winded about it. I can write
this script in about seven steps. I challenge you to do it in fewer.


Go to Next Field
Set Variable [$Start; Get(ActiveFieldName) ]
Loop
Set Field [no target field specified;
GetField ("RelatedTable::" & Get(ActiveFieldName)) ]
Go to Next Field
Exit Loop If [ $Start = Get(ActiveFieldName) ]
End Loop
Sorry, I didn't mean the script, but the design of having 500 fields
per record. )

Helpful Harry
Hopefully helping harassed humans happily handle handiwork hardships ;o)


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.