Dayalan Punniyamoorthy Blog

Thursday, May 4, 2023

EPBCS Groovy Rule series-1, Focused calculation based on the selected account!

This blog post will demonstrate how to carry out a targeted calculation using the accounts you've chosen from the Data Form's Page.


Product and Customers on the Rows, on the Data Form.

The Data Form allows for the selection of a single account from a group of accounts in order to perform the calculation. A specific calculation will be performed depending on the account chosen by the members on the POV and on the Page of the Data from the rule related to the Data Form.

Really neat and effective, huh?

Let's look at the Calculation rule that makes this possible.


The script generates a calculation script based on the edited cells in a data grid. It first creates a set called editedMembers to store the names of edited periods, years, products, and customers. The script then checks if any cells have been edited by checking the size of the editedMembers set, and if no cells have been edited, it prints a message and returns.

// Capture the edited periods and products

Set<String> editedMembers = []

operation.grid.dataCellIterator({DataCell cell -> cell.edited}, MemberNameType.ESSBASE_NAME).each { DataCell cell ->

        //editedMembers << cell.periodName << cell.getMemberName("Product")

        editedMembers << cell.periodName << cell.getMemberName("Years") << cell.getMemberName("Product") << cell.getMemberName("Customer")

    }

if(editedMembers.size() == 0){

    println("No edited cells found!")

    return;

}

Next, the script creates another set called editedAccounts to store the names of the edited accounts. The script then generates a calculation script based on the edited accounts. If one of the edited accounts matches a certain condition, the script generates a calculation script that contains the necessary operations to calculate revenue for the edited products. The cscParams function is used to generate a string that contains the point of view (POV) and edited members that will be used in the calculation script.


Set<String> editedAccounts = []

operation.grid.dataCellIterator({DataCell cell -> cell.edited}, MemberNameType.ESSBASE_NAME).each { DataCell cell ->

        editedAccounts << cell.getMemberName("Account")

    }

String calcScript = ""

// Generate the calc script to calculate revenue for the products whose volume was edited

if (editedAccounts.contains("Account1")) {

calcScript = """

    Fix(${cscParams(operation.grid.pov, editedMembers)})

    "OFS_Direct Input"

    (

       Some operations here

    )

    EndFix;"""

}

Finally, if no matching edited accounts are found, the script prints a message and returns it. If a matching calculation script is found, the script prints the generated script and returns it as a string.

if(calcScript == "") {

    println("No matching edited accounts found!")

    return;

}

this script is meant to automate the process of generating calculation scripts based on edited cells in a data grid.

The Complete Rule here, hope this helps.

Happy days on the cloud!!!



No comments:

Post a Comment