Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  • If configuration data is missing and calculation does not make sense without them, use api.throwException().
  • If missing or wrong values are allowed, you can solve it by using alerts (yellow, red, critical) or use api.abortCalculation(). 
    • You can create an additional field which shows to the user the alert reasons.

      Code Block
      languagegroovy
      titleSample
      def priceType = "CostPlus"
      
      def price = null
      def reason = "Unknown error"
      
      def targetMargin = api.getElement("TargetMargin")
      
      if (targetMargin) {
        def vat = api.getElement("VAT")
        def cost = api.getElement("Cost")
      
        if (if (out.cost && vatout.VAT != null) {
            price = out.cost * targetMargin * (1 + vatout.VAT)
            reason = "OK"
        } else {
          reason = "No Average or Calculated cost price in PX Cost_RRP or VAT defined"
          api.redAlert(reason)
        }
      } else {
        reason = "No target margin defined"
        api.redAlert(reason)
      }
      
      api.local.reason = reason
      
      return price