with warning - scd

// Trigger: ExpectedPaymentAmount_c // Event: After Field Update // 1. Initial filter to ensure logic only runs for the specific Action/Role def actionCode = nvl(BBActionManual_c, '') def isBonus = (nvl(IncentiveType_c, '') == 'BONUS') if (actionCode == 'MAV_DIR_BB_ACTION_1012' && nvl(SalesRP_c, '') == 'Y' && isBonus) { // 2. Precedence Logic: SCDEPA takes precedence over SCDCED // Note: These are formula fields, trigger reads their current calculated state def basePaysheet = (SCDEPAValue_c != null) ? SCDEPAValue_c : SCDCEDValue_c def bonusCED_val = CED_c // Only proceed if we have the necessary base data if (basePaysheet != null && basePaysheet != 0 && bonusCED_val != null) { // 3. Fetch Country Factor from Lookup String lookupTag = "1.0" def voLookUp = newView("CommonLookup") voLookUp.appendViewCriteria("LookupType = 'MTQ_ICM_BB_COUNTRY_LKP' AND LookupCode = '${EmploymentCountry_c}'") voLookUp.executeQuery() if (voLookUp.hasNext()) { lookupTag = nvl(voLookUp.next()?.Tag, "1.0") } try { // 4. Calculate Thresholds def tagLimitFactor = new BigDecimal(lookupTag.trim()) def absBaseAmount = (basePaysheet as BigDecimal).abs() def limitAmount = (absBaseAmount * tagLimitFactor).setScale(2, BigDecimal.ROUND_HALF_UP) def absBonusCED = (bonusCED_val as BigDecimal).abs() // Final allowed deduction ceiling (the lower of the two) def maxAllowed = (absBonusCED > limitAmount) ? limitAmount : absBonusCED // newValue is the value just entered by the user def currentInputAbs = (newValue != null) ? (newValue as BigDecimal).abs() : 0 // 5. Logic Check: If input exceeds the calculated limit if (currentInputAbs > maxAllowed) { def correctedEPA = (maxAllowed * -1) def formattedLimit = maxAllowed.toString() // 6. AUTO-CORRECT: Update the value using the safe method to avoid loops setAttribute('ExpectedPaymentAmount_c', correctedEPA) // 7. FIRE WARNING: Display the popup message // This format matches your requirement exactly String warnMsg = "EPA: SCD action must not exceed the relevant monthly commission payout of " + formattedLimit + "(Commission EPA/CED adjusted to SCD threshold of " + tagLimitFactor + " )" adf.error.warn(warnMsg) println("[EPA Trigger] Value corrected to ${correctedEPA} and warning displayed.") } } catch (Exception e) { println("[EPA Trigger] Error in calculation: " + e.getMessage()) } } }

Comments

Popular posts from this blog

dev7 from eror

EPA

Unified Currency Report- Krithika