2 Replies Latest reply on Jul 7, 2009 7:55 PM by thezed

    Issues with a loop script



      Issues with a loop script


      Hi, I am a newbie with FM and am trying to get a Loop script working. 


      My first table, Sales Invoices, contains all the invoices, each of them with a field Job Number (each invoice is indeed linked to a Job). There can be several invoices per Job Number. My second table, Job Numbers, contains all the jobs. In this table, i would like to add a field that gives the total amount invoiced per Job Number. 

      I have named this field Total_Invoiced and set its value to Calculation '=$$Sum', ie the result of the below script). But nothing happens....


      Set Variable [$$JN; Value:GetField (Job Numbers::Job Number)]

      Set Variable [$$Sum; Value:0]

      Go to Layout ["Sales Invoices" (Sales Invoices)]

      Go to Record/Request/Page [First]


         If [Sales Invoices::Job_Number = $$JN]

            Set Variable [$$Sum; Value:$$Sum + Sales Invoices::Amount USD

            Go to Record/Request/Page [Next; Exit after last]


            Go to Record/Request/Page [Next; Exit after last]

         End If

      End Loop

      Go to Layout [original layout]



      Thanks for your help! 

        • 1. Re: Issues with a loop script

          Howdy thezed,

          Thanks for the post.


          Out of my curious brain...is there a reason you want to do this in a script instead of just making the Jobs::TotalInvoiced field a calculation field of "Sum(Sales Invoices::AmountUSD)"


          You could have a portal in your Jobs table with Invoices and Amounts in the portal.  Then have a Calculation field on the layout with total amount invoiced.  No script needed.



          If there's another reason why you must have a script...note that I don't see anywhere in your script where you use the $$SUM variable to do anything.  You haven't said:  SetField[JobNumbers::TotalInvoiced;$$Sum] anywhere in the script.  You calculated what you wanted...but didn't park it anywhere on the record, just in the script variable that will be overwritten on the next loop through.

          • 2. Re: Issues with a loop script

            Thanks Ninja, quite easier with your solution!


            As for what I needed a script, I guess it is simply because I just discovered FM and didn't know it was so easy to use!


            Thanks again,