Forum Discussion

hraftery's avatar
hraftery
Contributing User
10 days ago

How to duplicate (verb) an invoice

While I found many references for duplicate (adjective) invoices, I couldn't find any guidance on duplicating an invoice. In other words, performing via the API the same function achieved by clicking the "Save and duplicate" button when viewing an invoice in the app.

 

I gather you can essentially POST an invoice you GET from Sale/Invoice/Item back to the same endpoint. But you need to strip at least some of the old fields out first so MYOB can create new records.

 

So I've tried removing the following:

 

  • UID

  • RowVersion

  • LastModified

  • URI

  • Number

And setting a new Date. But then it borks on "RowID not valid" for the Lines items.

 

Any ideas?

2 Replies

  • hraftery's avatar
    hraftery
    Contributing User
    7 hours ago

    Thanks Will, yeah this is what I've ended up doing out of desperation. It ended up being 50 fields removed, with a bunch of loops and null checks to deal with subfields. It works for me, but it took some trial and error and I consider it a hack. I certainly wouldn't claim it's reliable for anyone else.

     

    I've since repeated this technique to duplicate a Spend Money Transaction. "Only" 25 fields needed removing, some with subtle differences to an Invoice. Very hacky, but very happy to have something working.

     

    Thanks for the support link - I tried to make sure I was in the right spot but still managed to miss that forum!

  • Will_H's avatar
    Will_H
    MYOB Moderator
    8 hours ago

    Hi hraftery​
    In theory you'd just raise it like you would any other new invoice, as you said, with some of hte key fields removed.

    https://apisupport.myob.com/hc/en-us/articles/360000496176-Creating-a-new-invoice-AccountRight-API

    According to the linked docs:

    https://developer.myob.com/api/myob-business-api/v2/sale/invoice/invoice_item/

    The implication of the second is you should be removing:

    • UID
    • Lines.RowID
    • Lines.RowVersion
    • LastModified
    • RowVersion
    • LastPaymentDate


      I'd also consider if you need to remove any of these related to Terms
    • Terms

      It might be safest just to drop the entire Terms section, so they refresh off the customer.  If you aren't going to drop the entire terms section at least consider:

      • Terms.DueDate
      • Terms.DiscountExpiryDate
      • Terms.BalanceDureDate
      • Terms.DiscountDate
    • Order
      If you are Duplicating an invoice, then you probably need to make sure you're not linking the wrong sales order. (Or raise this via the Sales Order process instead)

     

    Note: I haven't directly worked with the AccountRight/Business API in a very long time, so I can't be treated as an authoritative source here.  If you need full help with that API reach out to the team via the help centre: 

    https://apisupport.myob.com/