Conditional Cell Coloring in data forms using Groovy

When it comes to highlighting certain data cells, we all must have got our hands on validation rules. Undoubtedly, they make things quite descriptive and help to control data entry when required. But at the same time, the trouble to maintain all these objects is equally troublesome.

Let’s take an example of a simple scenario,

  1. If the data is missing, color it light yellow
  2. If the no. of units is less than 10, color it yellow
  3. If the no. of units is more than 10, color it light blue
  4. If the no. of units is exactly 10, fill no color
  5. And make the Year Total value as Grey.

If we go for validation rules for this in form/s, we must set the required conditional formatting.

How about we have Groovy scripting capability in our application and lets see how Groovy makes our life easy by just maintaining a small piece of code which can be tagged to any form to serve the same purpose.

Let’s understand different parts of the code.

  • The 1st line points to the grid then each data cell iterates one after another.
  • 1st if statement checks whether the cell value is missing then assigns cell color as light yellow.
  • Similarly, the other 2 elseif checks the other two conditions and assigns color respectively.
  • To make grey color to all Year Total value, “YearTotal” is specified with the data cell Iterator. This iterates all cells within year total and assigns the color.

How To Create Groovy Script

From calculation Manager create a new rule and choose as edit script and script type as ‘Groovy script’.

   

Write the code and then validate and deploy the rule.

Add Rule to Form

Attach the rule to required data form. Check the ‘Run Before Load’ as BR property and Save the form.

Output

This groovy rule can have all such conditions listed together in single rule which can be attached to multiple data forms making them behave the same way. Even a more complex scenario will be easier to achieve through groovy rather than validation rule. With support for Groovy rules in Oracle EPM Enterprise Cloud, you can address all types of limitations. Groovy improves the performance by creating focused calculations. Dynamically generate calculation scripts at runtime based on contexts defined in the Groovy script. So Groovy scripting plays well with EPM and makes application work efficient and easier.