5 Replies Latest reply on Sep 17, 2009 5:25 AM by mrvodka

    Script problem

    Gengis

      Title

      Script problem

      Post

      Hi

      I hope this isn't too confusing but...

      I have been trying to find the problem with a script that using subscripts, first checks for unbilled items (time and materials) if it finds unbilled items it then creates a new invoice, setting the _kf_job Id field from a script parameter on the new invoice, Then taking the new _kp_invoice Id as a set variable, it then gets the description, cost, hours, and tax rate etc. again as set variables  first from the timeslips and then the supplied materials tables and creates new records in the invoice line items table and is supposed to set the foreign key field for the _kf_ invoice Id . It then sets the invoice line item id as a variable and puts this in the foreign key invoice line item field on the time or material record to avoid it being billed again.

      What I get is a new record with Id and a job Id in the foreign key job Id field, but a related field  customer name is blank and no items appear in the invoice line items portal on the new invoice layout

      The weird thing is that all the new records are in the  invoice line items table and are complete except for the new invoice Id, also when I check the relationships between the invoice and the job file tables just opening the relationships box seems to trigger the customer name field and when I return to the new invoice layout the customers name is there.

      If I set the _kf_invoice Id field on the invoice line items table manually then the items appear in the portal. I have checked for any type errors in the set variable names but it all seems okay, I have also checked all the relationships between the tables and it seems correct , it all works fine if I do it manually.

      The script was not my own invention I have adapted it from the script in the Missing manual book (Filemaker Pro 9) and again I have checked what I have done compared to the book and it seemsto be okay.

      Any ideas?

      Thanks

       

       

        • 1. Re: Script problem
          TSGal

          Gengis:

           

          Thank you for your post.

           

          If "new invoice Id" is blank, double check to make sure this is being entered with "Set Field" script step and the correct table is being referenced.  Halt the script after that step, and you should see where you are in the layout.

           

          TSGal

          FileMaker, Inc. 

          • 2. Re: Script problem
            Gengis
              

            Hi TSGal thanks for helping me with this

            I have been trying to get to the problem by testing the various script steps and  I think its something to do with the script parameters.

             

            Here is the -create invoice subscript, the script parameter is JobFiles:: _kp_JobId and the script is run from the JobFiles layout

             

            Go to Layout("Invoices"(Invoices))

            New Record/Request

            Set Field (Invoices::Job Id;Get (ScriptParameter))

            Set Variable($invoiceId;Value:Invoices::InvoiceID)

            Go to Layout(original layout)

            Exit Script (Result:$invoiceId)

             

            When I run this script I get a new record in the Invoices table with a the correct value in the Invoices::-kf-JobId field.

             

            To test this script result I made a new field in JobFiles called testresult and then made the following subscript. I set the script parameter to $invoiceId

             

            Go to Layout("JobFiles"(JobFiles))

            Set Field (JobFiles::testresult; Get(ScriptParameter)

             

            The testresult field remains empty

             

            Any ideas so far ?

             

             

             


             

            • 3. Re: Script problem
              mrvodka
                 Look into Get ( ScriptResult )
              • 4. Re: Script problem
                Gengis
                  

                Yes thats it

                instead of the script parameter being $invoiceId it should be  Get(Script Result),

                Thanks for the help Mr_Vodka the script now works fine, but why didnt it work the other way ?

                 

                • 5. Re: Script problem
                  mrvodka
                     Think of it this way... A parameter is a value passed in. A result is value passed out.