Setting user variable default values using Groovy

Groovy is a standard scripting language which is available in EPM applications to allow dynamic customisation in multiple contexts around the system. The availability of groovy is dependent on the EPM licensing; groovy scripting is available for EPM Enterprise applications only.

As with all coding languages, use of the documentation is key and Oracle have provided a brilliant scripting reference which can be found here: https://docs.oracle.com/en/cloud/saas/applications-common/22b/cgsac/groovy-basics.html

In this blog we will focus on setting user variable values using groovy. User variables are administered by individual users and can be used on forms to show only relevant information to the specific user. It is useful to set default values for users so that they can open forms which utilise the user variables, without having to manually set them first.  

In the below example, we will be using groovy to set a default value for the MyRegion user variable, which is setup for the Region dimension. This will pick up the first available region member for the user, depending on the security for the user that runs the rule.

The below script performs the following steps:

  1. Check whether the user variable has a value, or not (i.e. is null)
  2. If null, then retrieve the Region dimension
  3. Set member function to retrieve all Region members under ALLREG (All Regions)
  4. Check number of region members that user has security access to
  5. If members are available, set the MyRegion user variable to the first available member
  6. Print a line in the log to indicate the setting

 

if(operation.application.getUserVariable('MyRegion').getValue()==null){

    //MyRegion User Variable is not selected

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

    Dimension dim = cube.getApplication().getDimension('Region');

    String memberfunction = 'ALLREG,Descendants(ALLREG)'

    def mems = dim.getEvaluatedMembers(memberfunction,cube)

    if(mems.size()>0){

      operation.application.setUserVariableValue(operation.application.getUserVariable('MyRegion'),mems[0])

      println "MyRegion User Variable is selected to " + operation.application.getUserVariable('MyRegion').getValue()

    }

}

else {

println "MyRegion User Variable is selected to " + operation.application.getUserVariable('MyRegion').getValue()

}

Save this script in a business rule, with a relevant name, making sure to select the rule type as groovy. Then assign the business rule to a task list, or a form in the navigation flow, for each user to run before opening any forms which utilise the user variables.

Comments

Popular posts from this blog

Executing Smart View Retrievals using VBA

Loading Actuals from Fusion ERP Cloud to PBCS

Loading multi-period row data files using Data Management