Groovy
scripting,
which allows automation, dynamic validation, and metadata updates.
In
this weblog, we’ll stroll by two Groovy enterprise guidelines that handle model
members within the Model dimension:
- Creating
a brand new model dynamically - Renaming
an current model member
We’ll clarify the logic
behind every rule,
Rule
1: Making a New Model Dynamically
Use
Case
Organizations
typically must create archived variations of Precise information for historic
comparisons. This rule ensures {that a} new model member, similar to Archive_Actual,
is created below Archived Precise Variations whereas stopping duplicates.
Step-by-Step
Breakdown
1.
Outline Error Messages
Person-friendly
error messages are outlined utilizing messageBundle to enhance script
maintainability.
def
mbUs = messageBundle([
“validation.memberexists”: “🚨 The member ‘{0}’ already exists and cannot be
created.”
])
def
mbl = messageBundleLoader([“en”: mbUs])
2.
Retrieve the Model Dimension
We
entry the Model dimension utilizing the operation.utility.getDimension()
methodology.
Dimension
versionDim = operation.utility.getDimension(“Model”)
3.
Get the Dad or mum Model Member
We
establish the mother or father below which the brand new model might be added.
Member
parentVersion = versionDim.getMember(“Archived Precise Variations”)
4.
Validate if the Member Already Exists
Earlier than
creating a brand new member, we examine if it already exists below the mother or father. If it
does, we veto the operation with an error message.
String
newMemberName = “Archive_Actual”
if
(parentVersion.hasChild(newMemberName)) {
throwVetoException(mbl,
“validation.memberexists”, newMemberName)
}
5.
Add the New Member as a Dynamic Little one
If
the validation passes, we create the brand new member dynamically.
Member
newVersion = parentVersion.addDynamicChild(newMemberName)
println
“✅ Efficiently added new model
member: ${newVersion.identify}”
6.
Print Execution Abstract
A
last message is logged with the executing person’s identify.
println(“Rule
was executed by ${operation.person.fullName}”)
Validation
carried out,
- Use hasChild() to
forestall duplicates. - Throw a
significant error
as a substitute of permitting silent failures. - Preserve logs
informative
for debugging and auditing functions.
Rule
2: Renaming an Current Model
Use
Case
Over
time, organizations could must rename archived forecast variations for higher
monitoring. This rule renames Archive_Actual to a brand new identify supplied through a Runtime
Immediate (RTP).
Step-by-Step
Breakdown
1.
Begin Execution and Retrieve Runtime Immediate
The
script begins execution, and we retrieve the brand new member identify from the Runtime
Immediate.
println
“🚀 Beginning Rename Member Rule
Execution…”
String
oldMemberName = ” Archive_Actual “
String
newMemberName = rtps.NewMemberName
2.
Retrieve the Model Dimension
We
fetch the Model dimension from all obtainable cubes.
println
“🔍 Retrieving ‘Model’
dimension…”
Dice[]
cubes = operation.utility.getCubes()
Dimension
versionDim = operation.utility.getDimension(“Model”, cubes)
if
(versionDim == null) {
throwVetoException(“🚨 The ‘Model’ dimension couldn’t be
discovered.”)
}
3.
Verify if the Outdated Member Exists
Earlier than
renaming, we examine if the outdated member exists.
println
“🔍 Checking if ‘${oldMemberName}’
exists within the Model dimension…”
Member
oldMember = versionDim.getMember(oldMemberName, cubes)
if
(oldMember == null) {
throwVetoException(“🚨 The member ‘${oldMemberName}’ doesn’t exist and
can’t be renamed.”)
}
4.
Rename the Member
If
the member exists, we rename it.
if
(versionDim.hasMember(oldMemberName, cubes)) {
attempt {
oldMember.rename(newMemberName)
println “✅
Efficiently renamed $oldMemberName to $newMemberName”
} catch (Exception e) {
throwVetoException(“Error occurred
whereas renaming $oldMemberName. $e.message”)
}
}
else {
throwVetoException(“$oldMemberName is
not an current member”)
}
5.
Print Execution Abstract
println
“✅ Rule executed efficiently by
${operation.person.fullName}”
Finest
Practices
- Use hasMember()
to examine existence earlier than renaming. - Wrap
renaming in a try-catch block to deal with surprising failures. - Use throwVetoException()
for validation failures as a substitute of letting errors happen
unexpectedly.
You possibly can have one single rule to get the rtps and create that member too, the requirement i had wanted it to be 2 steps somewhat than a single step.
These
two Groovy guidelines exhibit how metadata administration in Oracle Cloud EPM
will be automated utilizing dynamic member creation and member renaming.
By following finest practices similar to validations, error dealing with, and
informative logging, we are able to guarantee strong and dependable enterprise guidelines.
When
to Use These Guidelines
✅ When needing to automate model
archiving
✅ When requiring dynamic member
creation
✅ When renaming members to take care of
readability
You possibly can invoke these guidelines through the pipeline and create a simplified strategy for the tip customers.