6 Replies Latest reply on Jan 3, 2013 10:17 AM by Kirk_1

    Loop in a Loop???

    Kirk_1

      Title

      Loop in a Loop???

      Post

           This is the script im working on.

           The way its written now, if there are only 2 records, it does not recognize that there isn't a 3rd and the value of $SecondAmoutAR and $ThirdAmoutAR are the same.

           I tried a loop after the blue "Go to Record/Request/Page [ First ] below but it didn't work.

           Is there a better way to do this? I will only have up to 3 redords that it finds. I need to name them seperatly, one for each.

           I thought of a portal but not sure how to name it if they are different... $firstAmoutAR, $secondAmountAR... for each record.

           Its alreday in the correct layout...

             
      •           #Corrected Invoices
      •      
      •           Enter Find Mode [ ]
      •      
      •           Set Field [ Invoice::INPosted; "yes" ]
      •      
      •           Set Field [ Invoice::IN_isChangedReceivable; 1 ]
      •      
      •           Perform Find [ ]
      •      
      •           Go to Record/Request/Page [ First ]
      •      
      •           Loop
      •      
      •           Set Variable [ $pro; Value:Invoice::IN__PKFlgsiProNumber ]
      •      
      •           Go to Layout [ “LI_list” (InvoiceLineItem) ]
      •      
      •           Enter Find Mode [ ]
      •      
      •           Set Field [ InvoiceLineItem::LI_FKInvoice; $pro ]
      •      
      •           Set Field [ InvoiceLineItem::LIDateEntered; "12/31/2012*" ]
      •      
      •           // Set Field [ InvoiceLineItem::LIDateEntered; Get ( CurrentDate ) ]
      •      
      •           Perform Find [ ]
      •      
      •           Go to Record/Request/Page [ First ]
      •      
      •           Set Variable [ $firstAmoutar; Value:InvoiceLineItem::LIAmount ]
      •      
      •           Set Variable [ $firstDescar; Value:InvoiceLineItem::LIWhyChanged ]
      •      
      •           Go to Record/Request/Page [ Next  ]
      •      
      •           Set Variable [ $SecondAmoutAR; Value:InvoiceLineItem::LIAmount ]
      •      
      •           Set Variable [ $SecondDescar; Value:InvoiceLineItem::LIWhyChanged ]
      •      
      •           Go to Record/Request/Page [ Next ]
      •      
      •           Set Variable [ $ThirdAmoutAR; Value:InvoiceLineItem::LIAmount ]
      •      
      •           Set Variable [ $ThirdDescar; Value:InvoiceLineItem::LIWhyChanged ]
      •      
      •           Go to Record/Request/Page [ Next; Exit after last ]
      •      
      •           Go to Layout [ “LP_List” (PayableLineItem) ]
      •      
      •           Enter Find Mode [ ]
      •      
      •           Set Field [ PayableLineItem::LP_FKInvoice; $pro ]
      •      
      •           Set Field [ PayableLineItem::LPDateChanged; "12/31/2012*" ]
      •      
      •           // Set Field [ InvoiceLineItem::LIDateEntered; Get ( CurrentDate ) ]
      •      
      •           Perform Find [ ]
      •      
      •           Set Variable [ $firstAmoutAP; Value:PayableLineItem::LPAmount ]
      •      
      •           Go to Record/Request/Page [ Next ]
      •      
      •           Set Variable [ $SecondAmoutAP; Value:PayableLineItem::LPAmount ]
      •      
      •           Go to Record/Request/Page [ Next ]
      •      
      •           Set Variable [ $ThirdAmoutAP; Value:PayableLineItem::LPAmount ]
      •      
      •           Go to Layout [ “Corrections” (Corrections) ]
      •      
      •           New Record/Request
      •      
      •           Set Field [ Corrections::Cor_FirstCorrected_AR_Amount; $firstAmoutar ]
      •      
      •           Set Field [ Corrections::Cor_FirstCorrected_AP_Amount; $firstAmoutAP ]
      •      
      •           Set Field [ Corrections::Cor_SecondCorrected_AR_Amount; $SecondAmoutAR ]
      •      
      •           Set Field [ Corrections::Cor_SecondCorrected_AP_Amount; $SecondAmoutAP ]
      •      
      •           Set Field [ Corrections::Cor_ThirdCorrected_AR_Amount; $ThirdAmoutAR ]
      •      
      •           Set Field [ Corrections::Cor_ThirdCorrected_AP_Amount; $ThirdAmoutAP ]
      •      
      •           Set Field [ Corrections::Cor_FirstCorrected_AR_Desc; $firstDescar ]
      •      
      •           Set Field [ Corrections::Cor_SecondCorrected_AR_Desc; $SecondDescar ]
      •      
      •           Set Field [ Corrections::Cor_ThirdCorrected_AR_Desc; $ThirdDescar ]
      •      
      •           Set Field [ Corrections::Cor_PK_ProNumber; $pro ]
      •      
      •           Go to Record/Request/Page [ Next; Exit after last ]
      •      
      •           End Loop
      •      
      •           If [ Get ( FoundCount ) and not Get ( LastError ) ]
      •      
      •           Go to Layout [ “Print Corrected Invoice ” (Invoice) ]

        • 1. Re: Loop in a Loop???
          philmodjunk

               This step seems problematic:

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

               IF your find is only pulling up three records, this step is not needed and the "exit after last" parameter will kick you out of the loop prematurely. The steps inside the loop but folling this step won't be executed.

          • 2. Re: Loop in a Loop???
            Kirk_1

                 Exactly...

                 My problem is that the name of the field im looking for is LIamount. It represents each line item in the invoice. I need to capture them, if a condition is met.

                 How do set the $ varables with out going from record to record, if my field is has the same name?

            • 3. Re: Loop in a Loop???
              philmodjunk

                   Going from record to record is needed, but That particular script step may not be needed. IF your found set always finds 3 records, you just need to remove that script step.

                   (But there may be other ways to improve your script, I've just spotted a potential trouble spot without taking the time to make a detailed analysis of your script.)

              • 4. Re: Loop in a Loop???
                Kirk_1

                     It will have between 1 to 3

                     If i leave it, and have it go to the next one, and there are 2 record, its not recognizing there isn't a third one and the value of $SecondAmoutAR and $ThirdAmoutAR are the same.

                     How do i script that or set it up to resolve that?

                • 5. Re: Loop in a Loop???
                  philmodjunk

                       If the maximum is 3, you need to remove that script step as it is not needed.

                       There are two ways you can work with your 1 to 3 records, much depends on what you need to do when there is only 1 or only 2 records instead of 3:

                       1) You can put a loop inside the loop that loops through the 1-3 records.

                       2) You can use IF or Exit IF with this test:

                       Get ( RecordNumber ) = Get ( FoundCount )

                       To detect when you are on the last record.

                  • 6. Re: Loop in a Loop???
                    Kirk_1

                         Worked perfectly. i tired the loop in the loop last night, but with the cold medicine and the hour I'm sure i got it in the wrong spot

                          

                         Thank you