fixed code

//-Lookup validation String lookupMeaning_c = null // Initialize String lookupTag_c = null // Initialize def lookupType = 'MTQ_ICM_BB_COUNTRY_LKP' def lookupCode = EmploymentCountry_c println("[EPA Trigger] Lookup Attempt: VO='CommonLookup', Type=${lookupType}, Code=${lookupCode}") def voLookUp = newView("CommonLookup"); def str1SearchExpression = "LookupType = '${lookupType}' AND LookupCode = '${lookupCode}'" println("[EPA Trigger] Applying View Criteria: ${str1SearchExpression}") // 3. Apply the criteria and execute the query voLookUp.appendViewCriteria(str1SearchExpression) voLookUp.executeQuery() if (voLookUp.getEstimatedRowCount() > 0) { while(voLookUp.hasNext()) { def rowLookup = voLookUp.next(); // Retrieve attributes using nvl(value, default) for null-safe access // Assuming 'Description' is the Meaning and 'Tag' is the Tag attribute lookupMeaning_c = nvl(rowLookup?.Description, "") lookupTag_c = nvl(rowLookup?.Tag, "") // This is retrieved as a String // Break after finding the first match break } println("[EPA Trigger] Lookup Successful. Meaning: ${lookupMeaning_c}, Tag: ${lookupTag_c}") } else { println("[EPA Trigger] Lookup Failed: No matching row found for Type=${lookupType}, Code=${lookupCode}") } // Clean up the VO (optional but good practice) voLookUp.reset() // --- FIXED VALIDATION LOGIC START --- def limitAmount = null // Ensure all required variables are non-null and lookupTag_c is not empty if (MPAGenerated_c != null && TotalPaysheetAmountInLHC_c != null && lookupTag_c != null && lookupTag_c.trim() != '') { try { // 1. Convert the String tag to BigDecimal for safe calculation def tagLimitFactor = new BigDecimal(lookupTag_c.trim()) // 2. Calculate the limit amount, ensuring it's a BigDecimal and cap it to 4 decimals limitAmount = (TotalPaysheetAmountInLHC_c as BigDecimal * tagLimitFactor).setScale(4, BigDecimal.ROUND_HALF_UP) println("[EPA Trigger] Calculated Limit (4 Decimals): ${limitAmount}") // 3. Perform the validation comparison if (MPAGenerated_c > limitAmount) { // 4. Throw the exception, using the 4-decimal capped limitAmount in the message def formattedLimit = limitAmount.setScale(4, BigDecimal.ROUND_HALF_UP).toString() throw new oracle.jbo.ValidationException("EPA : MPA generated should not be greater than " + formattedLimit); } } catch (NumberFormatException e) { // Handle case where lookupTag_c is not a valid number println("[EPA Trigger] ERROR: Failed to convert lookupTag_c ('${lookupTag_c}') to a number. Skipping limit validation.") } } else { println("[EPA Trigger] WARNING: Limit validation skipped due to missing values.") } // --- FIXED VALIDATION LOGIC END ---

Comments

Popular posts from this blog

dev7 from eror

EPA

Unified Currency Report- Krithika