EPM GROOVY – Perform Focused Calculations Based on User Selection Rows/ Cells in Web Forms

EPM Groovy’s focused calculations based on the edited cells from the web forms are one of the most utilized features so far. But for focused calculation to work, the cells need to be edited so that groovy can identify the members for which it needs to execute the calculation. Oracle has recently provided an option to not just get the edited member combination but also get the selected member cells from the web form. This is helpful in webforms, which are read-only, where we can still execute the focused calculations based on the user-selected cells/rows.

GET SELECTED CELLS USING DATA CELL ITERATOR

Data cell iterator is commonly used to get the unique edited combinations from the webform. I have products in the below form where I try to select few cells and retrieve the product members selected by the user before the save operation.

Code to capture selected cells:

Groovy
//Using Data Cell Iterator
Set<String> selectedProducts = []
operation.grid.dataCellIterator.each { DataCell cell ->
    if (cell.isSelected()) {
        selectedProducts << cell.getMemberName("Products")
    }
}

println("User has selected below products:\n$selectedProducts")

Output from Job console:

GET SELECTED ROWS (CHECK IF ALL CELLS FROM A ROW IS SELECTED)

The idea is to capture the products if the entire row selected. As you know that the user can select only the visible columns, if the form uses any hidden column, this method wont work.

Code to capture selected cells:

Groovy
//Using DataGrid.row - get selected Rows from webform
List<DataGrid.Row> selectedRows = operation.grid.rows.findAll { it.data.any { it.selected } }

List<String> entireRowSelectedProducts = []

selectedRows.each { row ->
    //check if selected cells count equals to total cells in a row
    if (row.data.findAll { it.selected }.size() == row.data.size()) {
        entireRowSelectedProducts << (row.headers.findAll { it.dimName == 'Products' }.collect { it.mbrName }[0])
    }
}

println("Entire row selected for the below Products:\n$entireRowSelectedProducts")

Output from Job console: