2 Replies Latest reply on Sep 8, 2014 7:16 AM by philmodjunk

    loop in loop help

    ericjlindholm

      Title

      loop in loop help

      Post

      I have a script that adds inventory Items to an equipment list. 

      If the added item is a single inventory Item, one line item record is created

      If the inventory Item added is a system package, it adds related inventory items and deletes the originally selected item.    

      if the added item is a package, it adds the selected item's ID to a field called PKG header ID and is shown in a portal from the main line item.

       

      My issue is adding system packages that contain packages.  I cannot get the "add package contents" loop to run past one package creation.  It seems to just exit the script.  Attempts to run a loop checking for packages that don't have contents yet also result in only one package creation.  

      My current script is as follows.   It does not include the exiting loop

       

      Set Variable [ $PRodID; Value:Inventory Selector::ID ]

      Set Variable [ $$EQlistID; Value:Equipment List::id ]
      Set Variable [ $$EventID; Value:EVENT::Event ID ]
      Set Variable [ $CAT; Value:Equipment List::gCatsearch ]

      Freeze Window

      New Record/Request

      Set Field [ Line Items::EQ list ID; $$EQlistID ]
      Set Field [ Line Items::Inventory ID; $PRodID ]
      Set Field [ Line Items::master cat; $CAT ]
      Set Field [ Line Items::package sort name; Line Items::LI ID ] #SYSTEM PACAKGE
      If [ LI_Inventory::Package New="System Package" ]

      Set Variable [ $$SYS PKG DELETE; Value:Line Items::LI ID ]

      Set Variable [ $PKG LI ID; Value:Line Items::LI ID ]
      Set Variable [ $QTY; Value:Line Items::Qty quote ]
      Freeze Window

      Go to Related Record [ From table: “LI_Inventory Package Line Items”; Using layout: “Inventory Package Line Items” (LI_Inventory Package Line Items) ]
      [ Show only related records ]

      Loop

      Set Variable [ $INVID; Value:LI_Inventory Package Line Items::INV ID ]

      Set Variable [ $PKGQTY; Value:LI_Inventory Package Line Items::Qty ]

      Set Variable [ $pkgname; Value:LI_Inventory::cinternal item name display ]

      Go to Layout [ “Line Items” (Line Items) ]

      New Record/Request

      Set Field [ Line Items::Event ID; $$EVENTID ]

      Set Field [ Line Items::EQ list ID; $$EQlistID ]

      Set Field [ Line Items::Inventory ID; $INVID ]

      Set Field [ Line Items::Qty quote; $PKGQTY ]

      Set Field [ Line Items::package sort name; $pkgname ]

      Set Field [ Line Items::master cat; $CAT ]

      Failing loop Start***

      If [ LI_Inventory::Package New="Package" ]
      Set Variable [ $PKG LI ID; Value:Line Items::LI ID ] 

      Set Variable [ $QTY; Value:Line Items::Qty quote ] 

      Freeze Window

      Go to Related Record [ From table: “LI_Inventory Package Line Items”; Using layout: “Inventory Package Line Items” (LI_Inventory Package Line Items) ]
      [ Show only related records ]

      Loop

      Set Variable [ $INVID; Value:LI_Inventory Package Line Items::INV ID ]

      Set Variable [ $PKGQTY; Value:LI_Inventory Package Line Items::Qty ]

      Set Variable [ $pkgname; Value:LI_Inventory::Internal Description ]

      Go to Layout [ “Line Items” (Line Items) ]

      New Record/Request

      Set Field [ Line Items::Event ID; $$EVENTID ]

      Set Field [ Line Items::EQ list ID; $$EQlistID ]

      Set Field [ Line Items::Inventory ID; $INVID ]

      Set Field [ Line Items::Qty quote; $PKGQTY ]

      Set Field [ Line Items::package sort name; $pkgname ]

      Set Field [ Line Items::master cat; $CAT ]

      Set Field [ Line Items::PGK Hide; "Hide" ]

      Set Field [ Line Items::PGK Header ID; $PKG LI ID ]

      Set Field [ Line Items::Price per; "" ]

      Go to Layout [ “Inventory Package Line Items” (LI_Inventory Package Line Items) ]

      Go to Record/Request/Page

      [ Next; Exit after last ] End Loop

      Go to Layout [ original layout ]

      Failing loop End***

       

      Go to Layout [ “Inventory Package Line Items” (LI_Inventory Package Line Items) ]

      Go to Record/Request/Page

      [ Next; Exit after last ] End Loop

      Go to Layout [ original layout ]
      Go to Record/Request/Page [ $$rec id ]

      [ No dialog ]
      Go to Related Record [ From table: “Line Items”; Using layout: “Quote Input Empty Test GTRR” (Line Items) ]

      [ Show only related records; New window ]
      Perform Find [ Specified Find Requests: Find Records; Criteria: Line Items::LI ID: “$$SYS PKG DELETE” ]

      [ Restore ]
      Delete Record/Request

      [ No dialog ]
      Close Window [ Current Window ]

      End If

      #PACKAGE

      If [ LI_Inventory::Package New="Package" ]
      Set Variable [ $PKG LI ID; Value:Line Items::LI ID ]

      Set Variable [ $QTY; Value:Line Items::Qty quote ] 

      Freeze Window

      Go to Related Record [ From table: “LI_Inventory Package Line Items”; Using layout: “Inventory Package Line Items” (LI_Inventory Package Line Items) ]
      [ Show only related records ]

      Loop

      Set Variable [ $INVID; Value:LI_Inventory Package Line Items::INV ID ]

      Set Variable [ $PKGQTY; Value:LI_Inventory Package Line Items::Qty ]

      Set Variable [ $pkgname; Value:LI_Inventory::Internal Description ]

      Go to Layout [ “Line Items” (Line Items) ]

      New Record/Request

      Set Field [ Line Items::Event ID; $$EVENTID ]

      Set Field [ Line Items::EQ list ID; $$EQlistID ]

      Set Field [ Line Items::Inventory ID; $INVID ]

      Set Field [ Line Items::Qty quote; $PKGQTY ]

      Set Field [ Line Items::package sort name; $pkgname ]

      Set Field [ Line Items::master cat; $CAT ]

      Set Field [ Line Items::PGK Hide; "Hide" ]

      Set Field [ Line Items::PGK Header ID; $PKG LI ID ]

      Set Field [ Line Items::Price per; "" ]

      Go to Layout [ “Inventory Package Line Items” (LI_Inventory Package Line Items) ]

      Go to Record/Request/Page

      [ Next; Exit after last ] End Loop

      Go to Layout [ original layout ]
      Go to Record/Request/Page [ $$rec id ]

      [ No dialog ] End If

      If [ $$Cat = Line Items::master cat ]
      Go to Record/Request/Page [ $$rec id ]

      [ No dialog ]
      Go to Object [ Object Name: "Add" ]

      End If
      If
      [ $$Cat ≠ Line Items::master cat ]

      Go to Related Record [ From table: “Line Items”; Using layout: <Current Layout> ]

      Go to Object [ Object Name: "Add" ]

      End If 

       

      I know this is long and mind numbing.  Thank you for your help.

       

        • 1. Re: loop in loop help
          dbail22@comcast.net

          It is pretty difficult to see the problem in your code shown. Too many unknowns.... Many things cold happen from trying to create a record on the wrong table to not getting the expected results for the If statements.  If you have Filemaker Pro Advanced you should step slowly through the script.  If not you could put a custom dialog box at any early step to display what you think you expect and then move the dialog box through the code several steps at a time until you don't see expected results. Otherwise if you can make a very small file showing the problem you could post it for comment.

          • 2. Re: loop in loop help
            philmodjunk

            If you have FileMaker Advanced, I suggest enabling the script debugger and using it to walk through your script one step at a time to see where and why it doesn't work like it should. (When I concoct a long script I very frequently run it for the first time in the debugger so that I can spot and fix overlooked issues as I watch it step through the script one step at a time.)