3 Replies Latest reply on Apr 18, 2012 11:39 AM by philmodjunk

    Duplicating 2 levels on related records

    ericjlindholm

      Title

      Duplicating 2 levels on related records

      Post

      Duplicating Bill Of Materials (duplicating portal line items)

      I am building off the above linked post.

      I have Events with mulitple equipement lists with line items.  I want to duplicate the Event, its accociated equipment lists and line items.  Im sure how to stop a loop and get a new equipment list id varible and restart it. 

        • 1. Re: Duplicating 2 levels on related records
          philmodjunk

          It's a matter of adding another loop inside the loop already present in the sample script posted in that thread.

          What are the relationships that you have in place? Are they these?

          Event::EventID = EquipmentList::EventID
          EquipmentList::EqID = LineItems::EqID

          Event-----<EquipmentList------<LineItems

          I'm not sure why you need both an equipment list and also a LineItems table here.

          • 2. Re: Duplicating 2 levels on related records
            ericjlindholm

            That is correct. The event may contrain many equipment lists because there maybe two different delivery locations on one bill.

            • 3. Re: Duplicating 2 levels on related records
              philmodjunk

              The event may contrain many equipment lists because there maybe two different delivery locations on one bill

              Ok, but that doesn't absolutely require separate equipment list records for the same event--it's possible to just have a "location" field in LineItems and then you can pull up different sets of lineItems for a given event using that field. (A filtered portal, a filtered relationship or a find that constrains to just one location can all be done--plus, you can set up a summary type report that lists items from both locations but groups them by location.)

              Such a simplification of your table structure also simplifies this script, so consider it, but I fully understand that there may be other reasons for the added table and even if not, you may need such a script as a temporary fix until you can properly simplify your system design.

              Event-----<EquipmentList------<LineItems

              #Starts from Event based layout
              Freeze Window
              Set variable [$RecordNumber ; Value: Get ( RecordNumber ) ]
              Duplicate Record
              Set Variable [$EventID ; Events::kp_EventID ]
              Go To Record/Request/Page [$RecordNumber]
              If [ Not IsEmpty ( EquipmentList::kf_EventID ) // there are Equipment list records to duplicate ]
                     Go To Related Record [Show only related records; From table: EquipmentList ; Using layout: "EquipmentList" (EquipmentList)]
                     Go To Record/Request/Page [first]
                     Loop
                             Duplicate Record
                             Set Variable [$EQID ; EquipmentList::kp_EQID]
                             Go To Record/Request/Page [Previous]
                             If [ Not IsEmpty ( LineItems::kf_EQID) // there are line items to duplicate ]
                                     Go To Related Record [Show only related records; From table: lineItems; Using layout: "lineItems" (lineItems)]
                                     Go To Record/Request/Page [first]
                                     Loop
                                             Duplicate Record
                                             Set Field [ LineItems::kf_EQID ; $EQID ]
                                             Omit Record
                                             Go To Record/Request/Page [first]
                                             Omit Record
                                             Exit loop If [ get ( FoundCount ) = 0 ]
                                     End Loop
                                     Go To Layout ["EquipmentList" (EquipmentList)]
                             End IF
                             Set Field [ EquipmentList::kf_EventID ; $EventID ]
                             Omit Record
                             Go To Record/Request/Page [first]
                             Omit Record
                             Exit loop If [ get ( FoundCount ) = 0 ]
                     End Loop
                     Go To Layout [original layout]
                     Go To Record/Request/Page [Last]
              End IF