You'll need to enter the number into a field--simplest is a field with global storage and that's the assumption on which the following script is based:
Show Custom Dialog ["How many?" ] ----> specify YourTable::gQty, a global number field as an input field in this dialog
Set Variable [$K ; value: $K + 1 ]
Exit Loop If [ $K > YourTable::gQty ]
If you did not use a field with global storage for the Qty, you'd have to copy that value to a variable and use the variable in the Exit Loop If expression instead of just referring to the global field.
HI Phil Mod
I appreciate you taking time to reply I think my knowledge is a bit to basic for this forum, you lost me at
Show Custom Dialog ["How many?" ]
I added the number field suggested mine is called Qty I set it as global storage but that just puts the same value in every record. My duplication is not a fixed number.
Maybe if I explain what I am trying to achieve.
My database records items I have in stores for a number of customers.
Each item has to be recorded as a separate record so that I can in future book the item out to a different location or record damage of an item.
Its mainly office furniture. So under one job number I might have 1 desk, I table and 8 chairs, when first put into stock each chair will have identical characteristics so rather than typing the details 8 times or even trying to hit a duplicate button 8 times I would like a button script where I can enter the number of duplicate records of that item.
Yes but Qty is just used temporarily to specify the number of duplicate records to create. The fact that the same value is shown in every record is not only not a problem, it's necessary in order for the script, as written, to work correctly.
So if you want 8 "chair" records, you'd create the first one and then run this script. When the dialog asks for how many, you enter 7--which enters 7 into the Qty field and the the looping script creates 7 duplicates of the original. 7 duplicates + 1 original = 8 records.
You do not have to use Show Custom Dialog like this. This is just one method that enables the user to specify the number of duplicates. You could also just enter the value into the field on your layout and then click a button to run the script without using Show Custom dialog to ask for how many.
You can also use a non-global field, as I previously noted. It just makes the script a bit more complex as you have to set a variable to this value before duplicating records and your exit loop if step would compare $K to this variable instead of the global field.
Hi Phil Mod
I have been trying for a couple of hours and I know this seems like the simplest thing on earth to you.
From the info you gave me I have got line one complete but it wont let me enter line two it returns the error
A number text or constant field is expected here, and it highlights the first [ (the red below show the bit the wont work)
Set Variable [ $K; Value:"$k+1" ]
[ $K > Assets::Duplicate Item Qty::gQty ]
So I tried some bits and I seem to be able to get it to duplicate using this script below but it never exists the loop until I hit esc so it generate 10s of thousands of copies. My table is called Assets and the field I am entering the duplication quantity into is Duplicate Item Qty
Show Custom Dialog [ Title: "Do you have more"; Message: "How Many"; Default Button: “OK”, Commit: “No”; Button 2: “Cancel” ,
Commit: “No” ]
Set Variable [ $K; Value:$k+1 ]
Exit Loop If [ Assets::Duplicate Item Qty < 1 ]
I don't understand what $K means or what gQty means.
Hope you have time to help me again.
[ $K > Assets::Duplicate Item Qty::gQty ]
Where is the "Exit Loop IF" part of this script step?
the expression would be Assets::gQty not the text that you have here.
$K + 1 should not be in quotes in the preceding script step.
$K is a variable. All variables start with either $ or $$. Variables are a way to temporarily store a number or other data without having to define a field to hold it. In this example, you only need the one $ as part of the variable name.
gQty would be a field that you define in any one of the tables in this file. g is my naming convention for a field that has Global storage selected in Field OPtions for that field. This should be a field of type number with "global storage" specified for it in field options--a dialog you can open by double clicking a field's name inside Manage | Database | Fields.
I gave up on this for a while as I thought I would not need the function but now I do so I am looking at it again
The script works well except for one thing. After I enter the number of duplicate records I need and them click OK the custom dialog scripts repeats depending on the number of duplicates entered. For example if I enter 3 then the script loops 4 times so I have to repeatedly click OK. The after the final click of OK the records are duplicated the correct number of times.
Please can you advise, I attach a capture of the script
If you compare your script to my example, they aren't the same. You've placed the show custom dialog step after the Loop step and thus this dialog appears for each time this script loops. In my example, the show custom dialog is placed before the loop step and thus only executes once.
Thanks as ever PMJ
Hopefully last stupid question.
the cancel command - how do I get that to work at the moment it does the same as the OK button and makes the duplicates or do I have to just set the qty to 0 to make it work ?