AnsweredAssumed Answered

loop in loop help

Question asked by ericjlindholm on Sep 6, 2014
Latest reply on Sep 8, 2014 by philmodjunk

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.

 

Outcomes