new groovy
// Groovy Script for BBAction_c After Field Changed Trigger (Central Automation Hub)
// This script executes when BBAction_c is changed and acts as the central hub
// for all automation (prepopulation) logic driven by the BBAction value.
// --- Helper Function: Check for Null/Empty Fields ---
def areBeforeFieldsEmpty() {
// This function encapsulates the check for all mandatory "before fields" being null/empty.
// isAttributeNullOrEmpty() is the standard and safest way to check.
return isAttributeNullOrEmpty(HRStatus_c) &&
isAttributeNullOrEmpty(RoleName_c) &&
isAttributeNullOrEmpty(EmploymentCountry_c) &&
isAttributeNullOrEmpty(SalesRP_c) &&
isAttributeNullOrEmpty(EmployeeConsent_c) &&
isAttributeNullOrEmpty(HRTI_c) &&
isAttributeNullOrEmpty(CEDUSD_c) && // Included the CEDUSD_c field
isAttributeNullOrEmpty(cCED_c) &&
isAttributeNullOrEmpty(PTDEarnings_c) &&
isAttributeNullOrEmpty(BeginningBalance_c)
}
// --- End Helper Function ---
println("--- BBAction_c Central Automation Hub Fired ---")
// Use an if/else if structure to handle each distinct BBAction_c value based on the lookup codes.
if (BBAction_c == 'MAV_DIR_BB_ACTION_1005') {
// -------------------------------------------------------------------------
// RULE 1: Approve Beginning Balance (Pay Full BB Amount) - Lookup Code 1005
// ACTION: Prepopulate Reason and Comment
// -------------------------------------------------------------------------
println("DEBUG | Rule 1: Approve Beginning Balance Fired. (MAV_DIR_BB_ACTION_1005)")
BBReasonCode_c = 'Analyst to select'
BBMPAComment_c = 'Free style'
// MPAGeneratedExpectedPaymentAmount_c remains untouched ("MPA Auto prepopulate")
println("DEBUG | Action Success: Reason/Comment prepopulated.")
} else if (BBAction_c == 'MAV_DIR_BB_ACTION_1007') {
// -------------------------------------------------------------------------
// RULE 2: Hold Beginning Balance (Full BB on Hold until next month) - Lookup Code 1007
// ACTION: Set Reason, Comment, and Beginning Balance
// -------------------------------------------------------------------------
println("DEBUG | Rule 2: Hold Beginning Balance Fired. (MAV_DIR_BB_ACTION_1007)")
BBReasonCode_c = 'Analyst to select'
BBMPAComment_c = 'Free style'
// Reverse of BB = PTD earnings (Setting BeginningBalance_c to PTDEarnings_c)
BeginningBalance_c = PTDEarnings_c
println("DEBUG | Action Success: Prepopulated fields and set BeginningBalance_c = PTDEarnings_c: " + BeginningBalance_c)
} else if (BBAction_c == 'MAV_DIR_BB_ACTION_1008' || BBAction_c == 'MAV_DIR_BB_ACTION_1009') {
// -------------------------------------------------------------------------
// RULE 3 & 4: REC Payout Adjustment (1008) AND NN REC Payout Adjustment (1009)
// Both share the same prepopulation logic: Set Reason, Comment, and calculate EPA minus CED.
// -------------------------------------------------------------------------
println("DEBUG | Rule 3/4: REC Payout Adjustment Fired. (Codes 1008 or 1009)")
BBReasonCode_c = 'Analyst to select'
BBMPAComment_c = 'Free style'
// Expected Payout Amount: EPA minus CED
if (MPAGeneratedExpectedPaymentAmount_c != null && CED_c != null) {
def calculatedAmount = MPAGeneratedExpectedPaymentAmount_c - CED_c
// This prepopulates the Expected Payout Amount field with the calculation
MPAGeneratedExpectedPaymentAmount_c = calculatedAmount
println("DEBUG | Action Success: Expected Payout Amount set to EPA minus CED: " + calculatedAmount)
} else {
println("DEBUG | Action Skipped: Cannot calculate EPA minus CED; one or both source fields are null.")
}
} else if (BBAction_c == 'MAV_DIR_BB_ACTION_1010') {
// -------------------------------------------------------------------------
// RULE 5: MPA to Write Off - Lookup Code 1010
// ACTION: Conditional Expected Payout Amount setting based on HRStatus
// -------------------------------------------------------------------------
println("DEBUG | Rule 5: MPA to Write Off Fired. (MAV_DIR_BB_ACTION_1010)")
// Default settings
BBReasonCode_c = 'Analyst to select'
BBMPAComment_c = 'Free style'
if (HRStatus_c == 'T') {
// HR Status = T, SPIF: Auto prepopulate Expected Payout Amount as Zero
MPAGeneratedExpectedPaymentAmount_c = 0
println("DEBUG | Sub-Rule: HRStatus=T. EPA set to 0 (Auto prepopulate as Zero).")
} else {
// Default COMM scenario: Analyst to input. Prepopulate reason/comment only.
println("DEBUG | Sub-Rule: Default/COMM. EPA left for Analyst input.")
}
} else if (BBAction_c == 'MAV_DIR_BB_ACTION_1011') {
// -------------------------------------------------------------------------
// RULE 6: MPA to Payroll Collections - Lookup Code 1011
// ACTION: Set Reason, Comment, and Expected Payout Amount to CED
// -------------------------------------------------------------------------
println("DEBUG | Rule 6: MPA to Payroll Collections Fired. (MAV_DIR_BB_ACTION_1011)")
BBReasonCode_c = 'Analyst to select'
BBMPAComment_c = 'Free style'
// Expected Payout Amount: = CED (Auto prepopulate)
MPAGeneratedExpectedPaymentAmount_c = CED_c
println("DEBUG | Action Success: Expected Payout Amount set to value of CED_c: " + CED_c)
} else if (BBAction_c == 'MAV_DIR_BB_ACTION_1012') {
// -------------------------------------------------------------------------
// RULE 7: SPIF vs Comm Deduction - Lookup Code 1012
// ACTION: Set Reason, Comment, and calculate Expected Payout Amount (TWA - EPA)
// -------------------------------------------------------------------------
println("DEBUG | Rule 7: SPIF vs Comm Deduction Fired. (MAV_DIR_BB_ACTION_1012)")
BBReasonCode_c = 'Analyst to select'
BBMPAComment_c = 'Free style'
// Expected Payout Amount: TWA minus EPA (Using TWA_c as a placeholder for the TWA field)
if (TWA_c != null && MPAGeneratedExpectedPaymentAmount_c != null) {
def calculatedAmount = TWA_c - MPAGeneratedExpectedPaymentAmount_c
MPAGeneratedExpectedPaymentAmount_c = calculatedAmount
println("DEBUG | Action Success: Expected Payout Amount set to TWA minus EPA: " + calculatedAmount)
} else {
println("DEBUG | Action Skipped: Cannot calculate TWA minus EPA; one or both source fields (TWA_c or EPA) are null.")
}
// Re-incorporating your initial LOOKUP1 rule.
} else if (BBAction_c == 'LOOKUP1') {
// -------------------------------------------------------------------------
// RULE 8: LOOKUP1 (The original rule: set Reason if all BEFORE fields are null)
// -------------------------------------------------------------------------
def TARGET_ACTION_VALUE = 'LOOKUP1'
def TARGET_REASON_CODE = 'Analyst to select'
def allBeforeFieldsEmpty = areBeforeFieldsEmpty()
println("DEBUG | Rule 8: " + TARGET_ACTION_VALUE)
if (allBeforeFieldsEmpty) {
BBReasonCode_c = TARGET_REASON_CODE
println("DEBUG | Action Success: BBReasonCode_c set to '" + TARGET_REASON_CODE + "'")
} else {
println("DEBUG | Action Skipped: One or more fields were populated.")
}
} else {
// Handle any other BBAction_c values that don't require automation
println("DEBUG | No specific automation rule defined for BBAction_c value: " + BBAction_c)
}
println("--- BBAction_c Central Automation Hub Finished ---")
return
Comments
Post a Comment