Thoughts, ideas and solutions from a few EPM consultants.

Dynamic Calcs from FDMEE Event Scripts

In a recent project I came across a process the client wanted to keep intact that seemed easy enough in FDMEE. They had multiple calc scripts saved in text files with custom ##VARIABLES##. These needed to be parsed, replaced and executed before or after certain data loads. In the old FDM VB API ( there was an option available to pass in a calc script as a string for execution.

You can setup calc scripts and pass run-time substitution variables using FDMEE currently. However, it has a limited number of options when it comes to passing variables (like from event scripts on the fly). After looking over the FDMEE admin docs I wasn't able to find this method available. So I looked over the Essbase JAPI docs and I could see there was a method that allowed execution of dynamic calc scripts. So I decided to write a simple wrapper around the JAPI that allows for this functionality.

Jython Essbase Wrapper

Save here:

Open the file in your favorite text editor and edit the section that is labeled #Consts to suite your environment.

The following few methods handle the reading and parsing of the calc scripts from the file system. Save the following script to the same folder you saved the previous one.

    File name:

#Handles reading and returning as a string
def ReadFile(filename, path="D:\\FDMEE\\scripts\\calc\\"):
    import os
    script = open(path + filename, "r").read()
    return script

Sample usage:
replaces = { "##YEAR##": "FY15" }
ParseCalcScript(ReadFile(""), replaces)
Returns: Parsed script with replacements
#Handles parsing script and replacing variables
def ParseCalcScript(script, rep):
    import re
    #Replaces variables in script with replacement dictionary using regex
    rep = dict((re.escape(k), v) for k, v in rep.iteritems())
    pattern = re.compile("|".join(rep.keys()))
    text = pattern.sub(lambda m: rep[re.escape(], script)
    return text

#Handles running clear sample
def ClearScript(period, year, entity, api):

    #Replacement vars in script
    replacements = {
        "##PERIOD##": period,
        "##YEAR##": year,
        "##ENTITY##": entity

    #Read the script file
    scriptContent = ReadFile("")

    #Parse script with replacements
    finalScript = ParseCalcScript(scriptContent, replacements)


    return finalScript

Now lets include both of these these in an event script. For our example we will use the BefLoad event for our planning application.

    File name:
import sys

custLib = r'D:\FDMEE\data\scripts\custom\jython'

if custLib not in sys.path:

#Import custom code    
import essbase-api
from essbase-api import Essbase
import calc-lib as calcLib

    ess = Essbase()

    dynCalc = calcLib.ClearScript("JUN", "FY16", "I234537", fdmAPI)



So now when our BefLoad event runs the clear calc script will get executed. This little snippet of code and the Jython wrapper allows you to call scripts on a more granular level. This does run inline so if it's a long running calc the other jobs in process details will wait behind it.