Lookup code - new
String lookupMeaning_c = null // Initialize
String lookupTag_c = null // Initialize
def lookupType = 'TEST1'
def lookupCode = EmploymentCountry_c
println("[EPA Trigger] Lookup Attempt: VO='CommonLookup', Type=${lookupType}, Code=${lookupCode}")
if (lookupCode != null) {
try {
// 1. Get the View Object
def voLookUp = newView("CommonLookup");
// 2. Create the Search Expression using the required string criteria pattern
// Variable values must be enclosed in single quotes in the expression string
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()
// 4. Retrieve the row(s). Use while loop as per user's pattern.
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, "")
// 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()
} catch (Exception e) {
println("[EPA Trigger] WARNING: Lookup query failed with error: ${e.getMessage()}")
}
} else {
println("[EPA Trigger] WARNING: Lookup skipped because EmploymentCountry_c (Lookup Code) is null.")
}
Comments
Post a Comment