November 21, 200520 yr Newbies Hello, I'm tryig to write a script that reads thu 1 layout (table) and for each record it finds it inserts a record into another layout (table). The tables aren't identical. It is to populate an invoice line-item table prior to the invoice being displayed. The problem I'm getting is that when I switch layouts to insert the record I lose position in my original source layout, and the loop just carries on forever! I've searched through a few FM forums & web pages & can't see an obvious answer (usiing FM Pro 8 Advanced). I'm very new to FM so apologies if this is an obvious answer. Grateful for any help anyone can give. It's driving me nuts! Edited November 21, 200520 yr by Guest
November 21, 200520 yr Author Newbies Sorry - should have added that the 2 tables are not related to each other via relationships.
November 21, 200520 yr Create a second script for the creation of the record in the line items table. In that script do this: go to layout(the layout for this table) new record do what you need done go to layout(original) That's it. Perform this script inside the loop of the main layout being processed and you should have no problem. Alternatively, if the table were related, a simple Set Field from inside the loop would automatically create the record in the second file (if there was not already a related record, and the relationship is set to allow record creation). I like this method since if makes programming easier. Echo
November 22, 200520 yr Author Newbies Echo, Thanks very much for the quick response. I'll try it out tonight. Just to help my understanding - does this mean the record position in a script is local to that script instance? So by starting another script and going to a different layout in that sub-script this doesn't interfere with the current layout record position?
November 22, 200520 yr While I cannot give you a definitive answer on that question, in my experience that appears to be the case. Previous to FM7 we would do the same thing, except that the second script would reside in a different table/file and so definitely a different record pointer/environment etc. Since we can do all of this now within a single file and script in FM7 and later, it still makes sense to me that we need to split the function into two scripts as I am not sure where the record pointer ends up pointing if we do it in one script. Others can probably shed more light on this issue. Echo
November 23, 200520 yr Author Newbies Echo, just to confirm that worked fine. I used global variables to pass the data down to the called sub-script which did the insert, and when returned I had the same record position as before. Thanks for your help, Chris.
Create an account or sign in to comment