Wednesday, June 21, 2017

Groovy and Data Validation in EPBCS - Quick Tip


This post is about simple data form validations, preventing users form entering negative amounts in certain members, we all familiar with that request, we used to achieve this pre Hyperion Planning 11.2.2 by changing the java script files. Now thanks to EPBCS's Groovy capabilities, it is a piece of cake in the cloud! No need to locate server files or any of the hassle we used to go through, we just write a simple script and that's it!

To keep it simple and lite, I'll stick to my usual approach and use a simple form (minimized version of Product Revenue form in EPBCS's Financials dodel). The same form I used for my previous post.

I'll start with my Groovy script, it's pretty simple and straightforward.


1
2
3
4
// Validate negative value 
operation.grid.dataCellIterator{DataCell cell -> cell.edited}.each { DataCell cell -> 
if ((cell.data < 0)) 
cell.addValidationError(0xFF6347, "Cannot enter negative numbers") }

Layout of my data form:



I have two business rules attached to the form (one business rule and one Groovy script to be precise)



GroovyValidate is my validation script and OnSave is a simple BR that calculates Product Revenue (Volume multiplied by Average Price), and OBVIOUSLY, I'll run both rules after save.



Let me enter some data and confirm it's working:



You can see above I was able to save the negative values which means there is something wrong either with my script or the form. I ruled out the script because it's a simple if condition that is definitely working, so what is wrong exactly? Ok see below the data form execution options for the business rules, we have Before Save and After Save!! Interesting!



By defaults and after a decade working on Hyperion Planning, almost 90% of the cases I had to run the rule on save, and that was my obvious and default choice, well I was wrong! I corrected this and selected Run Before Save



And now I can't enter negative values:










Notice the form did not save and the cell March->Average Selling Price is still in edit mode, so is Volume -> Mar but because I'm highlighting the cell you can't tell. And If I hover the mouse over the highlighted cell I can see the tool-tip.



All I have to do now is simply change the negative value and I can proceed with my work.











What happens if I enter data in all cells will it work and randomly enter negative values here and there?









The answer is yes, it works just fine!












Remove the negative values and that's it!













Voila!

Another reason to...💕 EPBCS 

Update

Celvin Kattookaran was kind enough to highlight I was using an alpha version of the API library, and he hooked me up with the Oracle Dev team responsible for Calculation Manager/Groovy, I had a call with Ujwala Maheshwari from Oracle and she was kind enough to go through my code and highlight the changes, and recommended another and better way to write the same code which I will elaborate in future posts. If you look again at the code in this post you'll notice some changes from the initial version (the changes and recommendations will be explained in a separate post in the very near future)

Clarification:

I got a comment from an anonymous  user in the previous post, presumably from Oracle, so I'm going to quote it, it clarifies an assumption I made earlier that Groovy is only available for EPBCS, which is not the case...

Quote Start

A point of clarification: Groovy is technically made available for EPBCS App type which is different from saying it is only for EPBCS. There are three SKUs that customers can buy: PBCS; PBCS + 1 module option; EPBCS. If you buy the PBCS +1 module option you can still deploy the application as EPBCS App Type or convert from PBCS App Type to EPBCS App Type. It is just that contractually you can't deploy more than 1 module when you buy PBCS + 1 module. To get Groovy all you need is to have EPBCS App Type. To use groovy you don't even have to deploy any modules once you are in this EPBCS App Type. So technically it is available for PBCS as long as at least the PBCS + 1 module option is bought by the customer. You could be using just the custom cubes in EPBCS App Type and still use Groovy. There is no current plans to make it available for standalone PBCS. Hope this can be clarified in your future posts

End Quote


10 comments:

  1. Nice post.. Thanks for making realize of what Groovy is capable .. One question, from where did we find the function addValidationError?? Do we have any sort of document?? If possible can you list down the functions available in groovy??

    ReplyDelete
    Replies
    1. Thanks, well you can access the Groovy Doclet in Academy tab in EPBCS. addValidationError is a method in DataCell class, I can write a bit more about the available EPM classes in a future post

      Delete
  2. Very nice post!!!
    Do you know if is possible to toggle the trigger similar message and prevent saving in the on Premises version?

    ReplyDelete
    Replies
    1. Thanks Marco, sorry for the late reply! It's a tricky question, you and probably depends on your Planning version (pre/post ADF) but for sure it's not as straight forward as it's on the cloud.

      Delete
    2. Thank you, Omar, for your reply. The version is post ADF. Before it was possible to use the unsafe javascript. Now they have been banned and we are looking for another method. We really need it in order to avoid that data would be messed up by the users :)

      Delete
    3. Again apologies for the late reply, my email notifications don't work and I have a bad record of checking the comments section. I'll probably need more details to see what is the best workaround for you. It's tricky to get validations done in post adf Planning versions as you know already, I really need a specific case and maybe I can suggest a workaround. You can message me on LinkedIn (profile is linked to my blog) and I'll share my contact details (if you haven't solve this already).

      Delete
  3. good post Omar :) .hope you are doing good..

    Ricky :)

    ReplyDelete
  4. Hi Omar, do you know if this still works? I am having troubles with validations that used to work in the way you describe. But now, if a cell is edited and the validation error occurs on the edited cell, the background color does not change to the desired color - it stays the color of an edited cell.

    ReplyDelete