Thumper87 Posted September 12, 2010 Posted September 12, 2010 Hey guys, Im having trouble with a script, basically i have the following 5 fields (all text box) and 1 button to trigger script: Storage Type: Rack/Stack # Container Info: Starting Number: How Many To Create: Create Records (button) So now when i click the create records button i want filemaker to create as many records as "How Many To Create:" indicates but like i said im not sure how to do this, im sure it has something to do with a loop, but im really unsure on how to script it, been trying all night. any ideas?
bcooney Posted September 12, 2010 Posted September 12, 2010 I'm reluctant to answer this question, bcs what you're trying to do seems like a poor approach. I feel this way because you are asking for a starting number. What is this number? Hopefully, not a field to be used to identify whatever you're creating. I'd be happy to help you with the design of your system, as will others here. If you are willing, pls post a zipped clone of your file or a diagram of your tables and their relationships. All that said, here's the loop: How Many to Create should be a number field with global storage, gHowManytoCreate. Set $counter = 0 Loop New Record any Set Fields that you want set $counter = $counter +1 Exit Loop if $counter = gHowManytoCreate End Loop
bruceR Posted September 12, 2010 Posted September 12, 2010 FWIW I prefer to put the exit loop if statement at the top of the loop so the action is never performed if the exit condition has already been met.
LaRetta Posted September 12, 2010 Posted September 12, 2010 In addition to Barbara's approach, here's another (I already had the answer done so decided to include it since it also holds additional details) Use global fields to hold your selections, something like gStorageType, gRackStack# etc. Fill in your preference in each of the fields you have listed above then click your 'Create Records' button. Back up first and then pseudo script would then be something like: # first remove all existing records from the found set (this isn't required but it makes process easier and eliminates need to write to a counter) Freeze Window Go To Record/Request [ First ] Omit Multiple Records [ without dialog ; Get ( FoundCount ) ] # now you have no records so begin creating your new ones Loop Exit Loop If [ Get ( FoundCount ) = gHowMany ] New Record/Request Set Field [ StorageType ; gStorageType ] Set Field [ RackStack# ; gRackStack# ] ... repeat with all your fields End Loop You could also use Replace Field Contents[] after you create your records but I prefer to do it in the moment. If you wait until you are done, you risk possibility that someone else finds one of these new records and locks it. :wink2:
LaRetta Posted September 12, 2010 Posted September 12, 2010 (edited) Actually, since each of the records holds the same information, I would simply Duplicate after setting the first record, something like: # first remove all existing records from the found set (this isn't required but it makes process easier) Freeze Window Go To Record/Request [ First ] Omit Multiple Records [ without dialog ; Get ( FoundCount ) ] # now you have no records so begin creating your new ones # create your first record New Record/Request Set Field [ StorageType ; gStorageType ] Set Field [ RackStack# ; gRackStack# ] ... repeat with all your fields Loop Exit Loop If [ Get ( FoundCount ) = gHowMany ] Duplicate Record End Loop Sorry for changing my mind mid-stream but sometimes that happens. ^) UPDATE: However, I DO agree with Barbara that there might be a reason you should consider a different approach here. Edited September 12, 2010 by Guest Added update
comment Posted September 12, 2010 Posted September 12, 2010 If I understand the OP correctly, these records need to be created in a related table (e.g. adding a new storage box with 24 slots requires creating 24 new records in the Slots table, all related to the parent box record).
LaRetta Posted September 13, 2010 Posted September 13, 2010 (edited) Wow. I have no idea how you came up with that, Michael. I see not one word about slots, boxes or related records. I don't doubt you but I just don't see it! How do you know it is 24 new records? Was there, at one time, more information on this thread that I wasn't aware of? Well, if correct, then the script would be started with: # Create "new storage box" in Main table New Record/Request Commit Record # Grab the new Box records' primary key into variable Set Variable [ $boxID ; Main::StorageBoxID ] Go To Layout [ layout based upon Slots table ] # then the script I outlined but also adding this line to the first record creation ... Set Field [ Slots::BoxID ; $boxID ] ... etc But I'm scripting blind here and I'm not happy about it. More information would certainly help; either that or I need glasses! UPDATE: Blimey ... I don't know if Storage Type, Rack/Stack #, or Container Info are attributes of the box or a slot. I take back all of my posts. I need more information here. :smile2: Edited September 13, 2010 by Guest Added update
comment Posted September 13, 2010 Posted September 13, 2010 Well, the words "storage", "rack", stack", "container", etc. are bell-ringers for me - as well as the need to create a specific number of "slots" (my term) when a new unit is added. The number 24 is only an example - the actual number should be in a field of the parent record. But it's still only guess, and we do need jcpython to clarify the request.
bcooney Posted September 13, 2010 Posted September 13, 2010 Hi Guys. Funny, we must be way too bored. As I said, I'm reluctant to answer until we know more of the purpose/need for such a script. But, went ahead anyway...my bad.
Geoffy1 Posted November 20, 2012 Posted November 20, 2012 Hey guys, Im having trouble with a script, basically i have the following 5 fields (all text box) and 1 button to trigger script: Storage Type: Rack/Stack # Container Info: Starting Number: How Many To Create: Create Records (button) So now when i click the create records button i want filemaker to create as many records as "How Many To Create:" indicates but like i said im not sure how to do this, im sure it has something to do with a loop, but im really unsure on how to script it, been trying all night. any ideas? Hello All! This is what I have been searching for in the forum....related to the above post. I have a roll-stock printing database in which I want to create a set of unique records based on a set or "How Many To Create" button which would be how many rolls can be cut from a larger "Parent Roll." The reason for the mass replication is to save time when in the production environment, the operator does not have time to create a single Child record from each Parent even with an Auto-Enter present. For Example: 1. Parent Roll can be cut down to 4 Children Rolls so the "4" value would be entered into the "How Many To Create Field" 2. Information (traceability info, paper lot numbers and such) is entered into the first set row which is then copied down by whatever the value is in the "How Many To Create Field" 3. The replication is continued until the information is changed in the row. It is troubling me on how to write this script. Any help is appreciated. G
comment Posted November 20, 2012 Posted November 20, 2012 Your request is not quite clear: 1. Parent Roll can be cut down to 4 Children Rolls so the "4" value would be entered into the "How Many To Create Field" Is this number decided by someone or can it be calculated from the parent roll's attributes? 2. Information (traceability info, paper lot numbers and such) is entered into the first set row which is then copied down by whatever the value is in the "How Many To Create Field" That's hardly a good idea. Data common to all children should be entered once into the parent record - not replicated among the children. This also raises the question regarding the purpose of the child records: so you will have 4 child rolls; what exactly will you do with them once you have them? Going by your description alone, they will be identical in every possible way - thus quite useless.
Vaughan Posted November 21, 2012 Posted November 21, 2012 Hi Guys. Funny, we must be way too bored. Actually, I'm too busy with real, paying work. Posts like this where the poster doesn't even try are starting to bug me. I need a holiday.
comment Posted November 21, 2012 Posted November 21, 2012 Actually, I'm too busy with real, paying work. Congratulations, you must be really busy - it took you two years to reply...
LaRetta Posted November 21, 2012 Posted November 21, 2012 Oh so funny!!! Thanks for the morning laugh guys!! :^)
Recommended Posts
This topic is 4385 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