Get Data of Previous Quote Revision

Sometimes it can be handy (i.e. in workflow) to get the data of the previous revision of the quote to do comparison to the current quote. As getting the itemLines can be a bit tricky, here is an example:

//we find previous revision of the quote if any
def prevRevUniqueName = quote.prevRev
if (prevRevUniqueName == null) {
   return // no previous revision found

//get the previous revision of the quote
def prevQuote = api.find("Q", Filter.equal("uniqueName", prevRevUniqueName))
if (!prevQuote) {
  return // could not get previous revision

//get the itemLines of the previous quote
def prevLineItemsCollection = api.getCalculableLineItemCollection(prevQuote[0].typedId)
def prevLineItems = prevLineItemsCollection?.lineItems

Line items have the same LineId between revisions (unless they were removed in the new revision). This is important to know if you want to compare the line items between the versions.