Sandy R Posted June 28, 2004 Posted June 28, 2004 How can I iterate through a set of fields both to read and write them? For example I have one set of fields (call them sourceFields) and another set of fields (call them destinationFields). I've placed the names of the fields in value lists. I want to create a script or custom function that allows me to copy the contents of all the source fields and put them into the destination fields. I assume I can use Get Field for some of this but I'm stumped as how to write into the field ...I'm just a confused (and this shouldn't be hard!) newbie...thanks...Sandy
Sandy R Posted June 28, 2004 Author Posted June 28, 2004 Thanks but I'm not THAT dumb ;-) I'd like to do something like Set Field(Get Field(destinationFields); GetField(souceFields)); which sits in a loop iterating through all the fields in the value lists...Sandy
-Queue- Posted June 28, 2004 Posted June 28, 2004 You can't use GetField( ) to specify a field to set. However, you can leave the field to be set unspecified and it will default to the one the cursor is currently in. So if you have a layout with all the fields you want set and say, a relationship to the source fields, you could loop using Go to Next Field and Set Field[ , GetField("relationship::" & Get(ActiveFieldName)], for example.
bAttitude Posted June 28, 2004 Posted June 28, 2004 I'm new to FM. I was confused by SetField() 'cause there was no GetField(). I have programmed in C for 17 years, btw. This is a new environment to me. It turns out that SetField( tmpGlobal, srcFld); SetField( dstFld, tmpGlobal) does the trick. re: the flying pig What is up with a response like _that_ ? Its worse than no answer. A pointer to a working example is about as easy to type, infinitely more helpful, and perhaps shows that you, flying pig, do know something about the environment after all.
bAttitude Posted June 28, 2004 Posted June 28, 2004 ok, there is no Script Step called GetField(), but there is a function ? Functions are used inside a ScriptStep to build a value, it seems...
-Queue- Posted June 28, 2004 Posted June 28, 2004 Yes, in my example, GetField( ) is a function used within the Set Field script step, specifying the field from which to retrieve the data.
QuinTech Posted June 28, 2004 Posted June 28, 2004 bAttitude, you'd be surprised the number of questions that are resolved through simple answers like Fitch's. Surely you know the tech support rule of simplest solution first? I learned a lot from Fitch (and others) on a similar message board many years ago, and i bet some of his replies to me were as short as the one above. And he didn't even get the satisfaction of typing "RTFM." Jerry
Fitch Posted June 28, 2004 Posted June 28, 2004 bAttitude: Look at the original post. I see the word "newbie." I don't see the function "Set Field" mentioned. So that is the first thing I suggest. Now, if Sandy had mentioned that he/she already knew about that function, my reply would have been different. Before you judge me, why don't you read through some of my posts. You will see that I almost never ask a question, I come here to answer questions. Over 1000 times, I have done this. Why I do it, I'm not sure. Yes, my answers are often short and to the point. But if I'm asked a follow-up, I do my best to work with the person until he/she understands. OK, enough of that. If you happen to see a pig flying overhead, I hope you brought an umbrella.
Sandy R Posted June 28, 2004 Author Posted June 28, 2004 For the record...I take no offense at the filying pigs response (great logo btw)...my response to many clueless users is..."Is it plugged in?" Sandy
Fenton Posted June 29, 2004 Posted June 29, 2004 I agree that, if you want something modular to set a great many fields with a short "generic" script, then using "Go to Next Field", then Set Field ["", "data"] (ie., ignore and do not target the Set Field), are part of the answer. To do this with a Loop is absolutely layout dependent; there can be no extraneous fields on the layout, and you must know when to stop; either what the count is or the last field. But it doesn't answer the 2nd part of the operation, as to where the data to be set is coming from, and how to loop through it. I assume you're parsing that out of a list. As long as you don't do anything that pulls the cursor out of the field you should be alright. Anyway, for an example of the basic modular method to walk through the fields, take a look at this example file, which is similar to one I just did, but modified to do a "list." ParseList.zip
bAttitude Posted June 29, 2004 Posted June 29, 2004 Remarkable! In this thread - a perfectly good example of a valid beginner's question - we now have quite a contrast in answers. On the one hand, the shall we say 'inattentive and less than helpful' answer from a well-intentioned vetran, and on the other, a fully generalized parsing routine with loop from another vetran. Lively indeed. It looks like the function FieldNames() returns a CR delimited list of field names. By using couple of global vars, parse the list one name at a time, and use the field by name to set the target in the SetField() script step. I had no idea that could be done in FM.
LaRetta Posted June 29, 2004 Posted June 29, 2004 Hmmm, well I'm going to add to it, as the process of using FieldNames() is one of my favorites, bAttitude. An easy demo, Sandy, can be downloaded here It uses a Developer layout to hold the fields from which it works, whatever you drop on it. More than the Duplication process itself, it shows multiline (Value List) manipulation and the power of FieldNames(). I haven't viewed Fenton's demo yet but will. I like his work. And easy up there a bit ... Our varied teaching & assistance styles is what makes FileMaker Forums so great. I, on the other hand, talk too much... LaRetta
bruceR Posted June 30, 2004 Posted June 30, 2004 I'd like to do something like Set Field(Get Field(destinationFields); GetField(souceFields)); which sits in a loop iterating through all the fields in the value lists Set field works fine in applescript. Here's one way. The technique can be "universalized" to work with any source and target database. This example only works with one database. Assume you have created global repeating fields gSource and gTarget to hold the source and target field names: copy ID of current record to oldRecID set NewRec to (create new record) go to NewRec copy cell "gSource" to sourceFields copy cell "gTarget" to targetFields repeat with num from 1 to count of sourceFields if item num of sourceFields = "" then -- skip else copy cell (item num of sourceFields) of record ID oldRecID to temp copy temp to cell (item num of TargetFields) of current record end if end repeat
Robert Kidd Posted June 30, 2004 Posted June 30, 2004 If you are going to loop though fields on a layout it is worth noting the "Go To Field Next" will step through the fields on the layout IN TAB ORDER.
Leader Posted July 9, 2004 Posted July 9, 2004 There is a guy on the forums with a tongue like barbed wire, so this is all pretty tame. Unlike me, of course, who is always the perfect gentleman. (bow) Frankly, I this thread better than average because it contained two of the 'things we should know but tend to forget' reminders, like Kidd's comment on tab order and Queue's reminder that you don't have to specify a target field in scripts as long as it's selected.
Leader Posted July 9, 2004 Posted July 9, 2004 That was supposed to read "I rate this thread better than average..." BTW, In the spirit of reminders, I also meant to add the obvious preface to Queue's comment about not setting a field name, is that you can initially select with the 'go to field' script step.
Recommended Posts
This topic is 7512 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