Dayalan Punniyamoorthy Blog

Saturday, May 31, 2025

Mastering EpmScript in Oracle Cloud EPM Groovy Rules!

 If you're building Groovy business rules in Oracle Cloud EPM, you've likely encountered EpmScript. It's not a class you import or instantiate—it's just there, quietly offering its powerful methods to control almost every part of your Planning application.

In this blog, we’ll demystify EpmScript, explore its capabilities, and walk through practical examples of how it unlocks dynamic planning automation.

What is EpmScript?

EpmScript is the base class for all Groovy rules in Oracle EPM Planning. Its methods are globally available, meaning you can call them directly without creating an instance.

Think of it as the operating system of your Groovy script: it lets you access the application, runtime prompts, metadata, and more.

What Can You Do with EpmScript?

Here are some of the key things EpmScript enables:

TaskMethod
Access runtime promptsgetRtp(name) or getRtps()
Access the current applicationgetApplication()
Get members of a dimensiongetMembers(dimensionName)
Create or modify metadatacreateOrUpdateMembers(dimensionName, members)
Access all cubesapplication.getCubes()
Get dimensions in cubesApplication.getDimensions(cube)

Let’s explore each of these through examples.


Accessing Runtime Prompts

If your script uses Runtime Prompt Variables (RTPs), EpmScript.getRtps() is your gateway.


/* RTPS: {varVersion}, {varScenario} */
String scenario = rtps.varScenario.memberName String version = rtps.varVersion.memberName

Here, rtps is the result of EpmScript.getRtps()—and you always need the /* RTPS: */ comment to declare them.


Getting the Current Application and Its Cubes

Application app = application  // shortcut for EpmScript.getApplication()

List<Cube> cubes = app.getCubes()


You can loop through all cubes to do operations like validation, loading, or metadata exploration.

Querying Dimension Members

Want to list all accounts? Easy:

List<Member> accounts = getMembers("Account")

accounts.each { println it.name }


This gives you access to metadata in a readable and scriptable form.

Creating or Updating Members

Need to add new members to a dimension? Here's how to do it with EpmScript.createOrUpdateMembers():


/* RTPS: */


DimensionBuilder builder = application.getDimensionBuilder("Account")

builder.addMember("NewRevenue", "Revenue")  // add NewRevenue under Revenue

builder.build()  // apply changes



In this example:

  • We get the dimension builder for "Account".

  • We define a new member under "Revenue".

  • We commit the changes with build().

Dynamic Metadata Scripting

/* RTPS: */

String month = new Date().format("MMM").toUpperCase()
String year = new Date().format("yy")
String versionName = "${month}${year}Archive"

DimensionBuilder builder = application.getDimensionBuilder("Version")
builder.addMember(versionName, "All Versions")
builder.build()


Avoid def keyword – Always use explicit types (String, Cube, etc.).

Use .memberName and .data on RTPs – Know what you’re pulling.

Don’t forget your RTPS comment – It’s required for prompt recognition.

Filter before looping – Use findAll before each to keep scripts performant.

Use .withCloseable {} for grids – Ensures resources are cleaned up.


Hope this is helpful!

No comments:

Post a Comment