Iterating over Web Forms

Iterating over Web Forms

Learn how to iterate over a Web Form using Groovy


By far the most common purpose of a Business Rule is to perform some logic on the data that has been saved on a Web Form. The only caveat is that we take the RTPs to get the member names, assume some others and provide a range for the rows and columns.

When developing Groovy rules, we can iterate over the Web Form — and some other neat tricks!

Iterating over a Web Form

For today’s purposes, I will be using the Revenue Direct Entry form that is available in the demo application using the out-of-box Financial Planning model. Just to be clear, Groovy is not limited to the out-of-box model and these concepts can be applied to any application (custom or otherwise) and to any Web Form.

No alt text provided for this image
Revenue Direct Entry Web Form with some random numbers

You can create your Groovy rule and attach it to the Web Form to ‘Run on Save’ (specially useful for an upcoming use case).

/*RTPS:*


operation.grid.dataCellIterator.each { DataCell cell ->
 println ("${cell.getMemberNames()} : ${cell.getData()}")
}/        

That’s all you need for the Groovy rule. Once you attach it to the form, just hit Save and you can then check the Jobs for the output. I am not performing any action at the moment, just printing it all out.

No alt text provided for this image
Job Log showing all the cells on the Web Form with the dimension intersection and value for each

Here’s the log so it’s more readable

Log messages :
[OFS_Product Revenue, Jan, OFS_Direct Input, Vision Entity, OEP_Plan, OEP_Working, USD, No Services, FY24, No Product, No Department] : 2.0
[OFS_Product Revenue, Feb, OFS_Direct Input, Vision Entity, OEP_Plan, OEP_Working, USD, No Services, FY24, No Product, No Department] : 2.0
[OFS_Product Revenue, Mar, OFS_Direct Input, Vision Entity, OEP_Plan, OEP_Working, USD, No Services, FY24, No Product, No Department] : 2.0
[OFS_Product Revenue, Q1, OFS_Direct Input, Vision Entity, OEP_Plan, OEP_Working, USD, No Services, FY24, No Product, No Department] : 6.0
...
...
...
[OFS_Material, Apr, OFS_Direct Input, Vision Entity, OEP_Plan, OEP_Working, USD, No Services, FY24, No Product, No Department] : 1.0
[OFS_Material, May, OFS_Direct Input, Vision Entity, OEP_Plan, OEP_Working, USD, No Services, FY24, No Product, No Department] : 1.0
[OFS_Material, Jun, OFS_Direct Input, Vision Entity, OEP_Plan, OEP_Working, USD, No Services, FY24, No Product, No Department] : 1.0
[OFS_Material, Q2, OFS_Direct Input, Vision Entity, OEP_Plan, OEP_Working, USD, No Services, FY24, No Product, No Department] : 3.0
...
...         

So we’ve basically picked up each and every cell and read the data. Let’s go to our Rules and run the same script.

No alt text provided for this image
Groovy Rule without a Web Form

When I run this rule,

No alt text provided for this image
I get an error saying that the “grid” property is not valid

When we are iterating over the cells, we had made a call to “operation.grid”. The “grid” property of “operation” gives us the DataGrid that is the Web Form. However, running the rule directly doesn’t give us a grid because it hasn’t been triggered from a Web Form.

To block this from happening, and not giving the impression that something is wrong with our script, let’s make a small fix.

/*RTPS:*


if (!operation.hasGrid()) {
 throwVetoException("This rule can only be run from a Web Form")
}


operation.grid.dataCellIterator.each { DataCell cell ->
 println ("${cell.getMemberNames()} : ${cell.getData()}")
}/        

We’ve simply made a check in the beginning and prompt the user that they must run this rule from a Web Form. Much more elegant than the “grid” missing error we got earlier, and also gives the user the information that they need to run this from a Web Form.

No alt text provided for this image
Users know that they need to run this from a Web Form



Head over to Medium to read the full post where I show you how

  • we can iterate over specific subsets of a dimension (Revenue Accounts)
  • we can iterate over subsets across dimensions (Revenue Accounts and Q1 Level 0 Periods only)
  • we can iterate over cells that have been edited

To view or add a comment, sign in

More articles by Shehzad Kazmi

Insights from the community

Others also viewed

Explore topics