13 Replies Latest reply on Jan 20, 2017 11:37 AM by LabsRock

    Go to Previous portal row.

    muhammad.ikram@contedia.com

      Hello Community,

      I would like some help with duplicating a portal row. I have an quantity field in portal. If user more than 1 quantity, I want it to duplicate that portal row according to the number of times quantity entered.

      This is my attempt but its doesn't work.

       

      What script shell i write so it goes to 2nd to last portal row or last added portal row.

       

      Thank you.

      Go to portal row [select; Last]

        • 1. Re: Go to Previous portal row.
          LabsRock

          Hello, if I understand what you are trying to accomplish, I would suggest a slightly different process.  Rather than trying to duplicate from within the portal, use a GTRR from the row you want duplicated and switch to the related table (personally, I'd open a new window as well).  From there duplicate the record the number of times you need it duplicated.  Once completed switch back to the original layout (or close the new window), refresh and flush, then go to the portal row you want.

           

          I hope that is helpful.

           

          Craig

          • 2. Re: Go to Previous portal row.
            philmodjunk

            There are two major problems with your current script:

             

            Commit records removes the focus from your portal row so you now longer have an active portal row once this step is executed.

             

            Duplicate Record duplicates the layout's record--the parent record, not the portal row record.

             

            Craig Miller has already outlined one method for doing what you want. If you have a workflow where the user enters data into multiple fields in the portal row before this script then duplicates it, it's probably the simplest approach.

             

            But if you the user does not need to enter data into a large number of fields in the portal row, you may want to websearch to look up MagicKey as a way to add multiple new records to your portal's related table of records.

             

            1) Magic Key does not require changing layouts nor opening a new window--which can trip script trigggers and (in some windows solutions) cause undesirable window resize issues.

             

            2) Magic Key can be set up so that this "batch record creation" takes place as a single database transaction that can be rolled back with a single revert records script step or menu option. (The revert isn't what makes this nice, it just proves that it's all one transaction. What makes ths a good thing is that if any kind of hardware or software glitch interrupts this process, you either get all the records created or none of them and that leads to much better data integrity in your system.)

            • 3. Re: Go to Previous portal row.
              muhammad.ikram@contedia.com

              Hello

               

              Thank you for responses.

               

              I tried Craig Miller method. I used GTTP, and than duplicate. It works but it duplicates the first row of the portal.

               

              When I add an order with more than one quantity, for example if I say 3 quantities for order A and click save button, the record will get saved but instead of duplicating the same record 3 times, it will duplicate the first record of the portal.

               

              Any changes I can make to my script.

              • 4. Re: Go to Previous portal row.
                philmodjunk

                Where is the focus when you run the script?

                 

                If the focus isn't in a particular portal row, GTRR will pull up all records in your portal with the first portal record as the current record. If the focus is on a row of the portal, you get the same found set, but the current record will be the portal row record.

                 

                So this isn't a "safe" script to run except from a button located inside the portal row so that the mouse click sets the portal row focus and runs the script. Even then, keep in mind that you will have a found set of more than just the one portal row record.

                • 5. Re: Go to Previous portal row.
                  muhammad.ikram@contedia.com

                  I believe once an order gets recorded in database, the focus moves to first row of portal. which than duplicates. I need a way to keep focus on the added row so GTTR duplicate the right row. 

                  • 6. Re: Go to Previous portal row.
                    BruceRobertson

                    Although it should possible to do this correctly, it also raises a question.

                    Why do this at all?

                    Especially when you're having trouble doing it reliably.

                    I don't recall seeing any other ordering systems set up this way.

                    How does adding this level of complication help the business?

                    • 7. Re: Go to Previous portal row.
                      muhammad.ikram@contedia.com

                      You are 100% right there BruceRobertson. It is not the perfect way.

                       

                      Since I only have been using FileMaker from just around 2 months, I didn't know the actual way.

                       

                      I have an order system where user can order more than one quantity. What I wanted was when user place an order with quantity, I can use script to duplicate the order by the number of times of quantity entered. This would allow me to treat each order differently as all duplicated rows will have own unique primary key.

                       

                      Do you know any better and more efficient way. That would be great help. 

                      • 8. Re: Go to Previous portal row.
                        BruceRobertson
                        What I wanted was when user place an order with quantity, I can use script to duplicate the order by the number of times of quantity entered.

                         

                        That isn't really an answer to the question.

                        I can't understand why you are doing it at all.

                        The customer placed an order with quantity.

                        You're done. Don't do anything else.

                        • 9. Re: Go to Previous portal row.
                          muhammad.ikram@contedia.com

                          The actual reason I was doing like that because when an ordered get's delivered, I wanted to attach credentials details e.g. username, password and serial No. This is for an computer parts application.

                           

                          If I just place an order with quantity, I cannot attach these credentials separately to the quantities of an order.

                          Each part in an order would have different credentials.

                           

                          That's why I was duplicating the order by the number of quantity, So I can attach different credentials to each of the item of that order.

                           

                          Hope this makes sense.

                           

                          ManyThanks 

                          • 10. Re: Go to Previous portal row.
                            philmodjunk

                            I need a way to keep focus on the added row so GTTR duplicate the right row.

                             

                            To repeat:

                            So this isn't a "safe" script to run except from a button located inside the portal row so that the mouse click sets the portal row focus and runs the script.

                             

                            And I don't think that duplicate record is the best option for you here. A looping script that simply creates new records and assigns the same product and invoice ID to each would achieve the same result without focus issues.

                             

                            Using MagicKey, you can even do this without leaving the current layout. Put a global field on the layout for selecting the product. Put another next to it for specifying the Qty. Then use those two values plus the ID of the current invoice record to create your individual line item records.

                            • 11. Re: Go to Previous portal row.
                              LabsRock

                              If your design needs to track variables for each item of a quantity ordered you might be best adding a separate table for that information (rather than duplicating line item records).  It seems it would be easier to do that than to create additional line item records.  Link that information to the line item by the line item id and your set.  You could use a popover to enter the additional information.

                               

                              You mentioned this is an older file, what version of FileMaker are you running?

                               

                              Craig

                              • 12. Re: Go to Previous portal row.
                                BruceRobertson

                                Separate table for shipment items. Yes. See attached example.

                                Screen Shot 2017-01-20 at 10.26.13 AM.png

                                • 13. Re: Go to Previous portal row.
                                  LabsRock

                                  Well Bruce beat me to the sample file, but I'll attach mine anyway.  I think his is perfect.  I've included a similar example using an additional table for the line item detail information (but with a slightly different layout design).  I've also included scripting that uses the first method I described (see DE_Invoices_2 layout).  Although I agree with the others that this may not be the best procedure, if it is what you need to use accommodate your current design and FMP version, the scripting should help you get started.  If you do need to go with the duplication of line items, I encourage you to try the Magic Key design as well.  If you can get a handle on that technique it may open a lot of other doors.

                                   

                                  I hope these help.

                                   

                                  Craig