Newbies Andy James Posted September 13, 2007 Newbies Posted September 13, 2007 I'm sure this has been asked many times, but it's a hard one to search for. Is there a way for a script to select which field to enter data into, based on a calculation? For what it's worth: I'm doing the old classic parts-assembly database. I want to the script to enter the ID of the current record into the join file either into the "Parent ID" field or the "Child ID" field, depending on the parameter passed to the script. But I seem unable to get FM to behave this way. (And yes, I know I can create related records through portals. I have my reasons not to wish to do so.) Any help?
Søren Dyhr Posted September 13, 2007 Posted September 13, 2007 Until fm8 arrived could it be solved via a recursive script, if you were to avoid the use of a global field: If [ IsEmpty(Get ( ScriptParameter )) ] Perform Script [ “New Script”; Parameter: theOne::RecordId ] Go to Layout [ original layout ] Else Go to Layout [ “theMany” (theMany) ] New Record/Request Set Field [ theMany::ForeignKey; Get ( ScriptParameter ) ] End If But then did $ $$ variables arrive with fm8, although there was one very snag to them, they would not pass the boundaries of the file, so if it's a migrated solution, and the variaous tables are splayed over several files - can't variables be used for such passings of values. Well the above script does it but are inconvenient to debug! Some days ago did I make a template utilizing a recursive structure, to exploit the GetNthRecord( function, instead of local variables or script paramters. http://www.fmforums.com/forum/showtopic.php?tid/189746/post/266141/#266141 However would i often tend to use this one - due to the simplicity.... --sd test2.zip
Newbies Andy James Posted September 13, 2007 Author Newbies Posted September 13, 2007 (edited) Søren: Thanks for the reply. I looked into your examples and now I think I must have written in a confusing way. I'll use an absurd but, I hope, clear example. Let's say I have a table with 3 fields: Field1, Field2, Field3. I want a script that accepts a field identifier as a parameter. Now the script passes a value (could be anything, let's say the word "cheese") into either Field1, Field2 or Field3, depending on the parameter passed. The problem is that the Set Field step does not seem to accept a calculation as a selecter for the field. Neither does Insert Text, Replace Field Contents or any of the other ways of putting text into a field. I have to specify, as a literal, exactly which field I mean in the script. I could write n scripts for n paramaters, but that's bad practice. Similarly, I could use case, but that's clumsy. Perhaps you answered my question already. If so, my apologies. Thanks for the help. Edited September 13, 2007 by Guest
Søren Dyhr Posted September 13, 2007 Posted September 13, 2007 So what you wrote later in your thread is of less importance, what you really is after is this: Is there a way for a script to select which field to enter data into, based on a calculation? And yes the threads title is slightly misleading, at least for me.... the confustion is the word select, as if you wish to pick something up, first I thought about: http://www.filemaker.com/help/FunctionsRef-37.html ...then did the join-table confuse me - but what you mean is to choose a target! Any way I'm i doubt here, when did "objects" arrive?? If your version facilitate them, could it be done this way: http://www.fmforums.com/forum/showtopic.php?tid/179836/post/219571/hl/indirection/fromsearch/1/#219571 But in case you ain't got objects yet - investigate template! --sd preObjStuff.zip
David Jondreau Posted September 13, 2007 Posted September 13, 2007 You are correct. There is no way to use the calculation engine to use the script step Set Field (or any of its equivalents). It's one of the most frustrating things for me. There are workarounds. Take your pick: 1) A series of If/Else If steps explicitly naming each field you want to test for, probably combined with Script Parameters (though not necessarily). 2) Naming the relevant fields on the layout (if they're on the layout) as objects and using Go To Layout Object. This issue is often referred to as "Set Field by Indirection" for purposes of searching.
Fitch Posted September 13, 2007 Posted September 13, 2007 If Andy's profile is correct (FileMaker 8), he won't have the luxury of named layout objects. That feature was added in 8.5.
Recommended Posts
This topic is 6282 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