It is good practice to check whether the data are complete and decide for an appropriate action.
- 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.
Sampledef priceType = "CostPlus" def price = null def reason = "Unknown error" def targetMargin = api.getElement("TargetMargin") if (targetMargin) { if (out.cost && out.VAT != null) { price = out.cost * targetMargin * (1 + out.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