Have you ever had a Groovy rule run successfully, but the data just didn’t write? What if I told you there’s a simple way around it?
The problem is… a Groovy rule saves data using the access of the user who runs it. If the user doesn’t have write access to an intersection, the rule still runs, but those cells get rejected.
No error but the data just isn’t there.
Most of the time, that’s exactly what you want. But there are cases where the user shouldn’t be able to edit a cell, yet their action should still update it.
Examples:
- Show who last updated the form – Users can only read that account, so nobody can type over it
- Intercompany entries – Input the matching intercompany entry in the other entity. The user doesn’t have write access to the partner entity.
- Change a flag that is controlled by admins only… etc.
This is where SYSTEM_USER becomes useful. If you set dataGridBuilder to SYSTEM_USER, the grid saves without checking the user’s write access.
Here is the script:
DataGridBuilder builder = cube.dataGridBuilder("MM/DD/YYYY", SYSTEM_USER)
This is an example script:
//Define CubeCube cube = operation.application.getCube("Plan1")//The user who saved the form for audit purposesString sUser = operation.user.fullName//Collect each edited Scenario, Version, Years and Entity onceList < List < String >> lstRow = []operation.grid.dataCellIterator({ DataCell cell - > cell.edited}).each { DataCell cell - > lstRow.add([cell.getMemberName("Scenario"), cell.getMemberName("Version"), cell.getMemberName("Years"), cell.getMemberName("Entity")]) }lstRow = lstRow.unique()if (lstRow.isEmpty()) { return}//Write data into grid using SYSTEM_USERDataGridBuilder builder = cube.dataGridBuilder("MM/DD/YYYY", SYSTEM_USER)//Every other dimension goes in the POVbuilder.addPov("BegBalance")builder.addColumn("Status_Flag")lstRow.each { List < String > lstMbr - > builder.addRow(lstMbr, [sUser])}//DataGridBuilder.StatusDataGridBuilder.Status status = new DataGridBuilder.Status()builder.build(status).withCloseable { DataGrid grid -> if(status.numRejectedCells > 0){ println("Total number of cells accepted: $status.numAcceptedCells") println("Total number of cells rejected: $status.numRejectedCells") println("First 100 rejected cells: $status.cellsRejected") } cube.saveGrid(grid)}
Attach it to the form and run it After Save.
Without SYSTEM_USER, the data gets rejected and the rule still completes… so the log is the only way to catch the real error.
Be careful when using SYSTEM_USER. It bypasses the access check for every cell in the grid, which means users may be able to write data to intersections they would not normally have access to.
Make sure the rule is designed appropriately and includes the necessary validations to prevent unauthorized data entry. You should also confirm that users have the appropriate write access to the target intersections before using SYSTEM_USER.
Hope this is helpful.
Leave a Reply