1 Reply Latest reply on Jan 25, 2012 11:40 AM by philmodjunk

    Duplicating an Invoice and its LineItems?

    FranzLang

      Title

      Duplicating an Invoice and its LineItems?

      Post

      Hello,

      I am using the following code (courtesy of jensteich) to duplicate an Invoice including its LineItems:

      Go To Layout [ MAIN ]
      #
      # Search by relationship of all the children
      Go To Related Records [ RELATED ; show only matching ]
      #
      # Jump back
      Go To Layout [ MAIN ]
      #
      # Duplicate MAIN Record and store ID
      Duplicate Record
      Set Variable [ $ID ; MAIN::ID ]
      #
      Go To Layout [ RELATED ]
      #
      Loop
      End Loop If [ Get( FoundCount ) = 0 ]
      Go To Record [ First ]
      Duplicate Record
      Set Field [ ID_Main ; $ID ]
      Omit Record
      Go To Record [ First ]
      Omit Record
      End Loop
      #
      Go To Layout [ MAIN ] 

      However, one little problem is that the "Amount" field of each LineItem is not duplicated properly. Instead, it is always set to "1", no matter what the original value is.

      I figured myself that this is because I have "1" as an Auto-Enter value.

      But how can I override this default and write the correct Amount into the duplicated LineItem?

        • 1. Re: Duplicating an Invoice and its LineItems?
          philmodjunk

          Does selecting "do not replace existing value" check box for this field make a difference?

          If not, you may need to capure the amount in a variable, then use set field to put the value back after duplicating the record.

          You do have another potentially serious isssue here. You use Go To Related Records without first checking to see if any related records exist. If you should ever run this script when you have no line item records, the Go To Related Records step will leave the current found set of records on the related records layout unchanged and thus a completely unrelated set of records might be duplicated by this script.

          Compare you script to the one used here to see an example of testing for the existance of related records:  Duplicating Bill Of Materials (duplicating portal line items)