Newbies Eryngium Posted June 11 Newbies Posted June 11 In a data table ("MASTER"), there are two three fields. These are: Key Text (with a variable number of words) Count (the number of words in Text; note these are different in different records) In a different data table ("PORTAL RECORDS")I wish to create a new record for each word in the MASTER text field. I created a layout with the three MASTER fields and a portal showing PORTAL RECORDS. PORTAL RECORDS has two fields: a key field (Key) and a text field (Word). They are linked by the Key field. This script will go into the portal, create a new record, and set the word from Text that corresponds to the particular portal row in the WORD field: Go to Portal Row (Next), Exit after last (off) Set Field ( PORTAL RECORDS WORD; MiddleWords, Get (ActivePortalRowNumber); 1) Everytime the script executes a new record is created in PORTAL RECORDS with the word corresponding to the portal row number. For example, if the 3rd word in TEXT is "dog" the third record created in PORTAL RECORDS will be "dog." However, if I try to set this up as a loop (i.e. with Go To Portal Row (Next), Exit After Last) it will continue creating new but blank records forever. Is there a way to have another script execute this script the number of times in COUNT? For example, Perform Script the number of times in the Count field? could set a variable or script parameter using Count, but how do I tell Perform Script to execute that many times? Any help is appreciated.
Ocean West Posted June 12 Posted June 12 I typically don't mess iterating portals in this case I create records by setting a global field to the UUID that will create a 1:1 relationship which you can set the data across that. test.fmp12 in any loop you need to declare the max repetitions and then an iterator that would increment the repetition then an exit loop to prevent runaway script.
Newbies Eryngium Posted June 12 Author Newbies Posted June 12 I don't understand your example, but it looks like the data that I need to separate (your "a", "b", "c" etc.) is already in separate records. Am I misunderstanding this? I've attached another solution, where I use the relationship between the active portal row number and the word count in the text field to control how many records are extracted (how many words are in the data field). This works well enough. But I'm still curious how a variable can be used to control how many times a script executes. Data Extraction Test.fmp12
Ocean West Posted June 12 Posted June 12 Here I have modified this to parse words in to records using a UUID create method. there is no need to filter your portal. Data Extraction Test.fmp12
comment Posted June 12 Posted June 12 (edited) 7 hours ago, Eryngium said: I'm still curious how a variable can be used to control how many times a script executes. Typically you would use two variables: one to set a limit to the number of iterations and one that increments on each iteration. In your example, it could look like: # CHECK IF RELATED RECORDS ALREADY EXIST If [ IsEmpty ( Child::ParentID ) ] Set Variable [ $parentID; Parent::ParentID ] Set Variable [ $text; Parent::Data ] Set Variable [ $n; WordCount ( $text ) ] Go to Layout [ Child ] Loop Set Variable [ $i; $i + 1 ] Exit Loop If [ $i > $n ] New Record/Request Set Field [ Child::ParentID; $parentID ] Set Field [ Child::ExtractedWord; MiddleWords ( $text ; $i ; 1 ) ] End Loop Go to Layout [ original layout ] Else Beep End If Often you can use a single variable for both purposes. If the order of the extracted words does not matter, you could start with the last word and decrease the $n variable until you run out: # CHECK IF RELATED RECORDS ALREADY EXIST If [ IsEmpty ( Child::ParentID ) ] Set Variable [ $parentID; Parent::ParentID ] Set Variable [ $text; Parent::Data ] Set Variable [ $n; WordCount ( $text ) ] Go to Layout [ Child ] Loop Exit Loop If [ $n = 0 ] New Record/Request Set Field [ Child::ParentID; $parentID ] Set Field [ Child::Extracted Word; MiddleWords ( $text ; $n ; 1 ) ] Set Variable [ $n; $n - 1 ] End Loop Go to Layout [ original layout ] Else Beep End If --- Not directly related to your question, but I feel compelled to add: This method works entirely at the data level. It does not depend on the existence of a portal on the layout; This method does not require adding anything (fields, table occurrences, relationships) to the file's schema. The entire logic is contained in the script alone. Edited June 12 by comment
Søren Dyhr Posted June 12 Posted June 12 (edited) 10 hours ago, Eryngium said: Is there a way to have another script execute this script the number of times in COUNT? For example, Perform Script the number of times in the Count field? could set a variable or script parameter using Count, but how do I tell Perform Script to execute that many times? This is another way to approach the matter, without the use of variables at all, but instead utilizing native filemaker functions: master.fmp12 Edited June 12 by Søren Dyhr
comment Posted June 12 Posted June 12 51 minutes ago, Søren Dyhr said: without the use of variables at all, but instead utilizing native filemaker functions: One could say that the reason to use variables is to avoid the added complexity ... 1
Søren Dyhr Posted June 12 Posted June 12 Well repeaters as source does not allow the update option to work, but a Dummy table can then receive splitted repeaters into indivual records, and from the Dummy into the portal, now allows the update and adds remaining. The scripts boils then down to 11 lines if the comments are omitted:
comment Posted June 12 Posted June 12 (edited) 40 minutes ago, Søren Dyhr said: The scripts boils then down to 11 lines This is the way I look at it: if we are going to run a script (as of course we are in this case), then as much as possible let's make the script do everything that's necessary and avoid splitting part of the logic off to other resources. And I'd rather have the script contain a few more lines to complete the task on its own, instead of adding resources to the file's schema that serve no purpose other than this task. Edited June 12 by comment
Søren Dyhr Posted June 12 Posted June 12 (edited) I’ve done stuff in this way for years, and find it much faster and more safe against recordlocking! But the present have a little flaw in not cleaning up the littering. —sd Edited June 12 by Søren Dyhr
comment Posted June 12 Posted June 12 24 minutes ago, Søren Dyhr said: a little flaw in not cleaning up the littering. No clue what you mean by that.
Søren Dyhr Posted June 12 Posted June 12 (edited) The import in the dummy should be erased at some point, if say you have this script running 10000 times each day, would it stack up - without being at much use to anyone! Yet another issue is, psos’ing as well as webdirect doesn’t support importing between internal tables that well! Edited June 12 by Søren Dyhr
Newbies Eryngium Posted June 12 Author Newbies Posted June 12 Thanks to all who have commented. I'll be out of town until next week, but then I'll explore these approaches. I've been using FM since way back in the early 90s, but programming has never been my thing!
Søren Dyhr Posted June 12 Posted June 12 If you're on a Mac OS version of Filemaker, could this be done instead - Which in my humble opinion is pretty fast and needs next to nothing to maintain. master.fmp12
Recommended Posts
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