Dayalan Punniyamoorthy Blog

Tuesday, May 20, 2025

Groovy most commonly used functions and codes!

 In the world of Cloud EPM Planning, where forms, calculations, and allocations rule the day—and multiple times, you need Groovy scripting to do what regular calc scripts simply can’t. This blog gives you the easy to use functions and codes that you can reuse work across projects.



Reading Inputs from RTP’s

 /* RTPS: {varScenario}, { varVersion } , {varPercent}  */

String scenario = rtps.varScenario.member.name

String version = rtps.varVersion.member.name

Double percent = rtps.varPercent.doubleValue / 100.0

Runtime Prompts (RTPs) let your users tell rule what to do without hardcoding.


Reading from Sub Var's

String year = operation.application.getSubstitutionVariableValue("DM_Fcst_First_FY")


Get Dimensions and Members

Dimension accountDim = operation.application.getDimension("Account")

List<String> accounts = accountDim.getEvaluatedMembers("ILvl0Descendants(\"Expenses\")", 


Retrieve a Cube and Read a slice of Data

Cube cube = operation.application.getCube("FinPln")


FlexibleDataGridDefinitionBuilder builder = cube.flexibleDataGridDefinitionBuilder()

builder.setPov("Forecast", "Working", "FY25", "Entity1")

builder.addColumn(["Period"], [["Jan", "Feb", "Mar"]])

builder.addRow(["Account"], [["Salary", "Bonus"]])

 DataGrid grid = cube.loadGrid(builder.build(), false)


Use FlexibleDataGridDefinitionBuilder - it lets you grab exactly the data you want from the cube. Always use this instead of the old DataGridDefinitionBuilder.


Loop Through

 

grid.dataCellIterator().each { DataCell cell ->

    if (!cell.missing) {

        println "Account: ${cell.getMemberName("Account")} Value: ${cell.data}"

    }

}


Writing Data Back

 

DataGridBuilder builder = cube.dataGridBuilder("MM/DD/YYYY")

builder.addPov("Forecast", "Working", "FY25", "Entity1")

builder.addColumn("Jan")

 

builder.addRow(["Salary"], [1000.0])

builder.addRow(["Bonus"], [200.0])

 

DataGridBuilder.Status status = new DataGridBuilder.Status()

builder.build(status).withCloseable { grid ->

    cube.saveGrid(grid)

}


Always write data with DataGridBuilder. Give it:

  • Your POV (what you're writing to)
  • The Period column(s)
  • The rows with data values


To create blocks in case of an BSO cube, 

builder.addRow(["Entity1", "COGS"], [0.0])  


Raise an Error if Needed

 

if (!operation.hasGrid()) {

    throwVetoException("Please save the form before running this rule.")

}

 

Use throwVetoException() when you want to stop execution with a clear error message.

 

Hope this is useful, happy days on the cloud!!!

No comments:

Post a Comment