In my previous post, I showed you how to setup Essbase API working directory and create a simple Groovy script. In this post, I will explain what the script is doing and how to run it.
First, I'm defining an Essbase connection and a cube to connect to
def essServer = IEssbase.Home.create(IEssbase.JAPI_VERSION
.signOn(user,pwd, false, null, "http://localhost/essbase/japi", "localhost")
def cube = essServer.getApplication("Sample").getCube("Sample"))
Define a member selection query on Cost Centre dimension and get all members.
def mbrSelection = cube.openMemberSelection("About to perform member selection"
mbrSelection.executeQuery("Cost Centre", IEssMemberSelection.QUERY_TYPE_DESCENDANTS, IEssMemberSelection.QUERY_OPTION_MEMBERSONLY,"Cost Centre", "", ""))
Get the members returned from the query, find all members with aliases that match the passed argument and print them all.
def mbrs = mbrSelection.getMembers()
def mbr = mbrs.getAll()
def searchResult = mbr.findAll{(it.getAlias(null) == null) ? "" : it.getAlias(null).toLowerCase().contains((args.length == 0 ) ? "" : args[0])}.each{println it.name+" : "+it.getAlias(null)})
Now I just have create a .groovy file in the same working directory and save the script.
To run the script, I just need to run it and pass the alias I want to search for.
For example, search for all cost centres with aliases that contain "ope".
groovy helloEssbaseCloud.groovy "ope"
As you can see, the script works without any issues. You can now use Groovy to work with Essbase Cloud APIs instead of Java.