Validation Rule

def FORBIDDEN_VALUES = [ 'MAV_DIR_BB_ACTION_1003', 'MAV_DIR_BB_ACTION_1000', 'MAV_DIR_BB_ACTION_1001', 'MAV_DIR_BB_ACTION_1013' ] // 2. Define the user identifier that should trigger this validation. // *** IMPORTANT: This must exactly match the string returned by adf.context.security.userName def TARGET_USER_ID = 'OIC1@nomail.com' // Get the current logged-in user's ID/Username def currentUserID = adf.context.getSecurityContext()?.getUserName() // BBAction_c holds the NEW value that the user has selected/entered. def newBBActionValue = BBAction_c // Check the original value of the field from the database/before modification. def oldBBActionValue = oldValue // Check 1: Has the field value actually changed from its original state? // Check 2: Is the new value in the forbidden list? (Updated logic using contains()) // Check 3: Is the logged-in user the target user? if (newBBActionValue != oldBBActionValue && FORBIDDEN_VALUES.contains(newBBActionValue) && currentUserID != TARGET_USER_ID) { // Set the custom error message. def errorMessage = "BB Action value cannot be changed to '" + newBBActionValue + "' by user '" + currentUserID + "'. The selected value is restricted. Please select another value." // For a Validation Rule, throwing the exception is the standard and most effective // way to stop the commit and display the error message against the field. throw new oracle.jbo.ValidationException(errorMessage) } // If the condition is not met (change is allowed, or different user), the script completes silently. return true

Comments

Popular posts from this blog

dev7 from eror

EPA

Unified Currency Report- Krithika