How to Configure Change History for Agreements & Promotions or Quotes

This article explains how to show changes between current and previous revisions of an Agreement/Promotion. In this particular case we created two different Condition Types: By Bulletin and By Product. So an Agreement/Promotion can have line items of the Bulletin or Product type. In order to configure the Change History tool, we need to define the Change History element in Administration > LogicsAgreements & Promotions Header Logics. Here is the Groovy code that will display the History element in Agreement/Promotion header output results.

def roundUp(numberToRound,roundTo)
{
      return Math.ceil(numberToRound/roundTo)*roundTo
}

def changeHistoryMatrix = api.newMatrix("Bulletin", "Product", "Previous Quantity", "Current Quantity", "Previous Into Stock Multiplier", "Current Into Stock Multiplier", "Previous Requested Multiplier", "Current Requested Multiplier", "Previous Gross Margin %", "Current Gross Margin %" )

def view = cProcessor.getContractView()
def prevRevUniqueName = view.prevRev

def prevRevision = api.find("CT", Filter.equal("uniqueName", prevRevUniqueName))
if (!prevRevision) {
     return
}

def prevLineItemsCollection = api.getCalculableLineItemCollection(prevRevision[0].typedId)
def prevLineItems = prevLineItemsCollection?.lineItems

for (line in view.lineItems) {
     if (line.folder) continue

     def currentBulletin = line.outputs?.find { it.resultName == "Bulletin" }?.result
     def currentProduct = line.outputs?.find { it.resultName == "Product" }?.result
     def currentQuantity = line.outputs?.find { it.resultName == "Quantity" }?.result
     def currentIntoStockMultiplier = line.outputs?.find { it.resultName == "IntoStockMultiplier" }?.result
     def currentRequestedMultiplier = line.outputs?.find { it.resultName == "RequestedMultiplier" }?.result 
     def currentGrossMargin = line.outputs?.find { it.resultName == "GrossMarginPercent" }?.result
     def currentGrossMarginPercent = roundUp((currentGrossMargin * 100),2) + " %"

     for (prevLine in prevLineItems) {
         if (prevLine.folder) continue

         def prevBulletin = prevLine.outputs?.find { it.resultName == "Bulletin" }?.result
         def prevProduct = prevLine.outputs?.find { it.resultName == "Product" }?.result
         def prevQuantity = prevLine.outputs?.find { it.resultName == "Quantity" }?.result
         def prevIntoStockMultiplier = prevLine.outputs?.find { it.resultName == "IntoStockMultiplier" }?.result
         def prevRequestedMultiplier = prevLine.outputs?.find { it.resultName == "RequestedMultiplier" }?.result 
         def prevGrossMargin = prevLine.outputs?.find { it.resultName == "GrossMarginPercent" }?.result
         def prevGrossMarginPercent = roundUp((prevGrossMargin * 100),2) + " %"

         if (prevBulletin == currentBulletin && prevProduct == currentProduct) {
              changeHistoryMatrix.addRow([
                  "Bulletin" : currentBulletin,
                  "Product" : currentProduct,
                  "Previous Quantity" : prevQuantity,
                  "Current Quantity" : currentQuantity,
                  "Previous Into Stock Multiplier" : prevIntoStockMultiplier,
                  "Current Into Stock Multiplier" : currentIntoStockMultiplier,
                  "Previous Requested Multiplier" : prevRequestedMultiplier,
                  "Current Requested Multiplier" : currentRequestedMultiplier,
                  "Previous Gross Margin %" : prevGrossMarginPercent,
                  "Current Gross Margin %" : currentGrossMarginPercent

              ])
         } 
    } 
}

cProcessor.addOrUpdateOutput (
        "ROOT",
        [  "resultName" : "ChangeHistory",
           "resultLabel": "Change History",
           "result" : changeHistoryMatrix,
           "resultType" : "MATRIX"
        ]
)


Contract Calculation Results (Unity UI)


Change History (Unity UI)