Dayalan Punniyamoorthy Blog

Thursday, February 8, 2024

Groovy rule to perform an action depends on the selected Scenario in the RTP!

This time, A different scenario was accomplished using the Groovy by one of my teammates. I thought of sharing here.

The requirement is to populate the Long-range planning and the rule will perform an action if the OEP_Plan (budget) is selected in the RTP and a different action if OEP_Actual (actual) is selected in the RTP.



In this scenario, we utilized Groovy known for its flexibility and simplicity, was employed to implement the necessary logic and actions based on these selections. Groovy's dynamic nature and concise syntax likely made it well-suited for handling such conditional tasks effectively.

The Rule 

/* RTPS: {Scenario} {Version} {Years} */

 String scenarioVariable = rtps.Scenario.enteredValue.trim()

String calcScript = ""

//Capture and print the Scenario entered.

println("RTP value: $scenarioVariable")

//The script if the Scenario selected is OEP_Plan.

if (scenarioVariable == '"OEP_Plan"') {

    calcScript = """

        FIX ("No FlexDimension")

            FIX(

                @Relative("Input Currencies", 0),

                @Relative("OEP_Total Entity", 0),

                @Relative("Total Product", 0),

                @Relative("Total Customer", 0),

                @Relative("Total Market", 0),

                @Relative("Total CostCenter", 0)

            )

            FIX(

                "Salable Units",

                "Avg Selling Price for Salable Units",

                "Avg Cost for Salable Units",

                @Relative("Management_hierarchy", 0)

            )

                FIX(@Relative("YearTotal", 0))

                    // Some calculations here.

                ENDFIX

            FIX("OEP_LRP", &LRP_Version, &LRPPreviousYr)

                "Dec"

                    (

                        // Some additional calculations here.

                    )

                ENDFIX

            ENDFIX

            ENDFIX

        ENDFIX

    """

//The script if the Scenario selected is OEP_Actual.

} else if (scenarioVariable == "OEP_Actual") {

    calcScript = """

        FIX ("No FlexDimension")

            FIX(

                @Relative("Input Currencies", 0),

                @Relative("OEP_Total Entity", 0),

                @Relative("Total Product", 0),

                @Relative("Total Customer", 0),

                @Relative("Total Market", 0),

                @Relative("Total CostCenter", 0)

            )

            FIX(

                "Salable Units",

                "Avg Selling Price for Salable Units",

                "Avg Cost for Salable Units",

                @Relative("Management_hierarchy", 0)

            )

                FIX(@Relative("YearTotal", 0))

                    // Some different calculations here.

                ENDFIX

            FIX("OEP_LRP", &LRP_Version, &LRPPreviousYr)

                "Dec"

                    (

                        // Some different additional calculations here.

                    )

                ENDFIX

            ENDFIX

            ENDFIX

        ENDFIX

    """

}

//If there is issue with creating the script 

 if (calcScript == "") {

    println("No input was found!")

    return

}

//Print the person who ran the script is captured in the jobs logs.

 println("The following calc script was executed by ${operation.user.fullName}:")

//Print the script that was created during the runtime.

println(calcScript)

 return calcScript.toString() 


Tada this is done. A big thanks to my teammate for this idea. 

Happy days on the Cloud!!! 



No comments:

Post a Comment