Lookup code function

// Function to fetch the lookup meaning (Display Value) def getLookupMeaning(lookupType, lookupCode) { // 1. Check for null/empty inputs if (lookupType == null || lookupType.trim() == '' || lookupCode == null || lookupCode.trim() == '') { println('DEBUG: Lookup Type or Code is null/empty. Returning null.') return null } // 2. Define the name of the standard Lookup View Object // This VO usually maps to the FND_COMMON_LOOKUPS table def lookupVO = newView('oracle.jbo.server.ViewObjectImpl', 'FndLookupTypeMeaningPVO') // 3. Create a View Criteria to filter by LOOKUP_TYPE and LOOKUP_CODE def vc = lookupVO.createViewCriteria() def vcr = vc.createViewCriteriaRow() // Set the criteria: LOOKUP_TYPE = 'your_type' AND LOOKUP_CODE = 'your_code' vcr.setAttribute('LookupType', '=' + lookupType) vcr.setAttribute('LookupCode', '=' + lookupCode) // Add the row to the criteria vc.addViewCriteriaRow(vcr) // Apply the criteria and execute the query lookupVO.applyViewCriteria(vc) lookupVO.executeQuery() println("DEBUG: Executed query for LookupType: ${lookupType}, LookupCode: ${lookupCode}. Row count: ${lookupVO.getEstimatedRowCount()}") // 4. Fetch the result def meaning = null if (lookupVO.getEstimatedRowCount() > 0) { // Get the first (and only expected) row def row = lookupVO.first() // Get the value of the 'Meaning' attribute (the Display Value) meaning = row.getAttribute('Meaning') println("DEBUG: Found Meaning: ${meaning}") } else { println('DEBUG: Lookup code not found.') } // 5. Clean up (important in Groovy scripts) lookupVO.closeRowSet() return meaning } // ============================================================================ // HOW TO USE IT IN YOUR FIELD TRIGGER // Example Scenario: Get the meaning of an MPA Status code // ============================================================================ // 1. Define your Lookup Type and the Code you want to fetch def myLookupType = 'OBA_MPA_STATUS' // Replace with your actual lookup type def myLookupCode = MPAStatus_c // Assuming MPAStatus_c is the field containing the code // 2. Call the function def myMeaning = getLookupMeaning(myLookupType, myLookupCode) // 3. Use the result if (myMeaning != null) { println("The Display Value for code ${myLookupCode} is: ${myMeaning}") // Example: Update another field with the meaning // MyDisplayField_c = myMeaning } else { println("Could not retrieve the display value.") }

Comments

Popular posts from this blog

dev7 from eror

EPA

Unified Currency Report- Krithika