10 Replies Latest reply on Jun 24, 2013 10:53 AM by philmodjunk

    Changing all discount of invoice product

    mplt

      Title

      Changing all discount of invoice product

      Post

           Hi everyone,

           I'm using the model "Invoices" provided with FMP 12. I want to add a button who will change all discount of the products in the invoice to the same value.

           Can't find out how to do it.

           Thank you.

           MPLT

        • 1. Re: Changing all discount of invoice product
          philmodjunk

               Change it for just the current invoice or for all future invoices as well?

               To just alter it for the current invoice would require using a script that modifies the value in the discount rate field in each Invoice Data record linked to the current invoice. If you add a field to Invoices to use for specifying the new discount rate, you can:

               Freeze Window
               Use Go To Related Records to bring up the related invoice data records on a layout based on Invoice Data
               Use Replace Field contents with the no dialog and calculation options selected to replace the value of the Invoice Data::Discount Rate field with the contents of the new field you just added to invoices.
               Return to your original layout.

          • 2. Re: Changing all discount of invoice product
            mplt

                 I have tried, this but it's not working.

                 The invoice table "Invoice" is using another table "Data invoice" to fill the lines in it. As defined in the sample provided by FMP.

                 Thank you.

            • 3. Re: Changing all discount of invoice product
              philmodjunk

                   Unless you have modified the design, the table is called Invoice Data and the script I have outlined will work for this.

                   What part of it is "not working"? HOW is it not working?

              • 4. Re: Changing all discount of invoice product
                mplt

                     Nothing is working, I have 7 lines in the invoice and none of them are modified.

                      

                     Thank you for your help.

                • 5. Re: Changing all discount of invoice product
                  philmodjunk

                       Please post the script that you have created.

                       To post a script to the forum:

                         
                  1.           You can upload a screen shot of your script by using the Upload an Image controls located just below Post A Answer.
                  2.      
                  3.           You can print a script to a PDF, open the PDF and then select and copy the script as text from the opened PDF to your clipboard for pasting here.
                  4.      
                  5.           If You have FileMaker Advanced, you can generate a database design report and copy the script as text from there.
                  6.      
                  7.           If you paste a text form of the script, you can use the Script Pretty box in the Known Bugs List database to paste a version that is single spaced and indented for a more professional and easier to read format.
                  • 6. Re: Changing all discount of invoice product
                    mplt

                         Here you go, really simple.

                    • 7. Re: Changing all discount of invoice product
                      mplt

                           Better in english!

                      • 8. Re: Changing all discount of invoice product
                        philmodjunk

                             You left out a step:Use Go To Related Records to bring up the related invoice data records on a layout based on Invoice Data

                             And don't forget that you need a field in invoices for specifying the discount rate that you want to apply to all items in the portal.

                             Freeze Window
                             If [ Not IsEmpty ( Invoice Data::Invoice ID match field ) // make sure that line items records actually exist ]
                                Go To Related Record [Show only related records; From table: Invoice Data; Using layout: "Invoice Details | iPhone" (Invoice Data) ]
                                Replace Field Contents [
                                Go To Layout [Original Layout]
                             End IF

                             Note: I specified "Invoice Details | iPhone" here, but any layout based on Invoice Data may be specified and this will still work, just make sure that there are no script triggers being tripped by the layout change that would interfere with this script.

                             An alternative method is to define a calculation in Invoices that applies the discount rate you specify to the invoice total as a whole instead of each individual line item.

                        • 9. Re: Changing all discount of invoice product
                          mplt

                                

                               I though that because I was already in the right table, right layout with right record, all I had to do was to add this script to a button on the invoice layout.
                                
                               Thank you from the beginner I am!
                          • 10. Re: Changing all discount of invoice product
                            philmodjunk

                                 You weren't on the "right layout" and thus were not on the "right table". This script changes context from Invoices to Invoice Data in order to make the needed "batch update" of your line items.