Hello,
I have my Groovy script for scenario and year changes, similar to the EPBCS Planning financial module. I have a form with the "run before save" function associated with my Groovy form, in which you select parameters using a smartlist. I have a condition where if the start of the budget year or the end of the budget year is less than the current year, I get a warning message. However, if I try to update it instantly without refreshing the form, it won't let me, even if I find the correct data. It seems to be blocked.
Example:
Current Year: FY24
Budget - Beginning Year: FY23 (Error message: "The Budget Year cannot be less than the Actual Year")
Budget - Ending Year: FY34
Current Year: FY24
Budget - Beginning Year: FY25 (Won't let me update)
Budget - Ending Year: FY34
Is there any way to do it?
//***********************************************************************//
// Define dimension, create an object
Cube cubeMain = operation.application.getCube("Main")
DataGridDefinitionBuilder builder = cubeMain.dataGridDefinitionBuilder()
// Define POV
builder.addPov(['Years','Period','Entity','Scenario','Version','Custom1','Currency','HSP_View','Cost Center'],
[['No Year'],['BegBalance'],['E70'],['No Scenario'],['No Version'],['No Custom1'],['CAD'],['BaseData'], ['No Cost Center']])
// Define Column
builder.addColumn(['Data Type'], [ ['Input']])
// Define Row
builder.addRow(['Account'], [ ['ILvl0Descendants("Period Stats")']])
// Build the grid
DataGridDefinition gridDefinition = builder.build()
// Load the grid
DataGrid dataGrid = cubeMain.loadGrid(gridDefinition, false)
// Message bundles for error handling
def mbUs = messageBundle([
"validation.missingmember.SmartVariables": "The following required fields are empty: {0}",
"validation.budgetyear.invalid": "The Budget Year cannot be less than the Actual Year",
"validation.incomplete.form": "Complete all required fields before saving"
])
def mbl = messageBundleLoader(["en" : mbUs])
// List of months
List months = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec']
// 1. COLLECTION PHASE - Collect all values first
Map<String, String> smartListValues = [:]
boolean allFieldsPresent = true
dataGrid.dataCellIterator.each { DataCell cell ->
String accountName = cell.getMemberName('Account')
String smartListValue = cell.DataAsSmartListMemberName?.trim()
smartListValues[accountName] = smartListValue
// Check if the required fields are present
if(['Period_Fiscal', 'Current_Fiscal Year', 'BegBudget_Fiscal Year', 'EndBudget_Fiscal Year'].contains(accountName) && !smartListValue) {
allFieldsPresent = false
}
}
// If not all fields are present, exit without error
if(!allFieldsPresent) {
println("Formulario incompleto - esperando que se llenen todos los campos requeridos")
return
}
// 2. VALIDATION PHASE - Check required fields only when all are present
List requiredAccounts = ['Period_Fiscal', 'Current_Fiscal Year', 'BegBudget_Fiscal Year', 'EndBudget_Fiscal Year']
List missingFields = requiredAccounts.findAll { !smartListValues[it] }
if(missingFields) {
throwVetoException(mbl, "validation.missingmember.SmartVariables", missingFields.join(', '))
}
// 3. CALCULATION PHASE - Process the collected values
// Process Fiscal Period (Current Month)
String mesActual = smartListValues['Period_Fiscal']
int currentMonthIndex = months.indexOf(mesActual)
int nextMonthIndex = (currentMonthIndex + 1) % months.size()
String MonthFcst = months[nextMonthIndex]
// Process Current Fiscal Year
String añoActual = smartListValues['Current_Fiscal Year']
String currentYearStr = añoActual.replaceAll("[^0-9]", "")
int currentYearNum = currentYearStr.toInteger()
String priorYearFormatted = "FY" + String.format("%02d", currentYearNum - 1)
String nextYearFormatted = "FY" + String.format("%02d", currentYearNum + 1)
String fcstYear = mesActual == "Dec" ? nextYearFormatted : añoActual
// Process Budget Years
String añoBegBudget = smartListValues['BegBudget_Fiscal Year']
String añoEndBudget = smartListValues['EndBudget_Fiscal Year']
int yearBegBudgetNum = añoBegBudget.replaceAll("[^0-9]", "").toInteger()
int yearEndBudgetNum = añoEndBudget.replaceAll("[^0-9]", "").toInteger()
// Validate that budget years are not less than the fiscal year
if(yearBegBudgetNum < currentYearNum || yearEndBudgetNum < currentYearNum) {
throwVetoException(mbl, "validation.budgetyear.invalid")
}
String BegBudgetYearFormatted = "FY" + String.format("%02d", yearBegBudgetNum)
String EndBudgetYearFormatted = "FY" + String.format("%02d", yearEndBudgetNum)
// Process Annual Years
String AnnualYears = smartListValues['Annual_Years'] ?: "No Year"
String EndMthlyYrsFormatted = AnnualYears == "No Year" ? EndBudgetYearFormatted : "FY" + String.format("%02d", AnnualYears.replaceAll("[^0-9]", "").toInteger() - 1)
…………
//***********************************************************************//
Best regards,
Diego Fuentes