In many processes, users select specific combinations before executing a set of rules. However, invalid selections can occur for various reasons—such as a newly implemented Chart of Accounts, user inexperience or incorrect Valid Intersection rules.
Rather than allowing the process to run and then identifying failures, a better approach is to validate selections upfront. Implementing a simple validation step at the beginning ensures that only correct inputs proceed, preventing errors before they impact the workflow. This not only saves time but also enhances user experience by providing immediate feedback, allowing adjustments before execution.
By shifting validation to the start of the process, we can create a more efficient, error-free, and user-friendly system.
Here is the idea, step 1 collect the information from the context whether it is an RTP, form or data points, step 2 create a virtual grid on the fly to targeted combination(s) and try to write data. step 3 check if virtual grid is successful continue process, if not stop execution.
To ensure user selections are valid before execution, we can implement a three-step validation process that leverages a virtual grid to simulate data writing before committing changes. Here’s how it works:
Step 1: Collect Contextual Information
Before executing the process, gather relevant context based on user selections. This may include:
- RTP (Run-Time Prompts): Capture user inputs such as entity, account, and period.
- Forms: Identify selected rows, columns, and filters.
- Data Points: Extract key values relevant to the process maybe smart list selections.
By collecting this information upfront, we ensure that the validation logic applies to the correct dataset.
Step 2: Create a Virtual Grid and Simulate Writing Data
Instead of immediately executing the full process, generate a virtual grid that mimics the data submission:
- Targeted Combinations: Construct a virtual grid based on user selections.
- Submit Data: Attempt to write data, send #Missing to avoid unnecessary block creation.
- Error Handling: Capture validation failures
If the virtual grid successfully processes the data, this indicates that the user’s selections are valid and access is in place.
Step 3: Validate Virtual Grid and Control Execution
- Successful Validation: If the virtual grid processes without errors, proceed with execution.
- Failed Validation: If the simulation fails, stop the execution and provide real-time feedback to the user, guiding them to correct their selections.
Providing a code example that you can build upon. I would recommend using a function within a template so that the code can be reused across multiple places in the application.
def checkValidComb(String entity, String costcentre){
def returnstatus
Cube cube = operation.application.getCube("myCube");
DataGridBuilder saveDataBuilder = cube.dataGridBuilder("MM/DD/YYYY")
saveDataBuilder.addPov('&SubvarExample','Base','0000000','No Product','&CurYear','&CurPeriod')
saveDataBuilder.addColumn('Dummy Account')
saveDataBuilder.addRow([entity,costcentre],['#Missing'])
DataGridBuilder.Status status = new DataGridBuilder.Status()
saveDataBuilder.build(status).withCloseable { grid ->
returnstatus="$status.numRejectedCells"
}
return returnstatus
}